summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazMalhotra2020-02-08 16:48:01 -0800
committerKazMalhotra2020-02-08 16:48:01 -0800
commitf81825697b3135c2c82bfbdd5f03f8ac8c7b96ea (patch)
treed8ae809d05c9122ba01921679861e4bf453ec3bc
downloadaur-f81825697b3135c2c82bfbdd5f03f8ac8c7b96ea.tar.gz
init
-rw-r--r--.SRCINFO13
-rw-r--r--PKGBUILD25
-rw-r--r--cws25
3 files changed, 63 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..2db2160cca3a
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,13 @@
+pkgbase = cws
+ pkgdesc = A CLI tool that finds the most common words in a file
+ pkgver = 1.01
+ pkgrel = 1
+ url = https://kazmal.tech/cws/
+ arch = any
+ license = MIT
+ depends = python
+ source = cws
+ md5sums = 8dc066695d6af82e9f2f6b8a96b892bf
+
+pkgname = cws
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..b0ee97fa7d0f
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,25 @@
+# Maintainer: Kaz Malhotra <kazmal@protonmail.com>
+
+pkgname='cws'
+pkgver=1.01
+pkgrel=1
+pkgdesc='A CLI tool that finds the most common words in a file'
+arch=('any')
+url='https://kazmal.tech/cws/'
+license=('MIT')
+depends=('python')
+source=("cws")
+md5sums=('92b48b83f0e6d60f103c2bc6d1184712')
+md5sums=('b6dfdfb3d79c0709e1154e9f55695726')
+md5sums=('8dc066695d6af82e9f2f6b8a96b892bf')
+
+package(){
+
+ echo installing...
+}
+
+
+build() {
+ sudo chmod +x cws
+ sudo cp cws /bin
+}
diff --git a/cws b/cws
new file mode 100644
index 000000000000..b5d3dfe0ece4
--- /dev/null
+++ b/cws
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+import csv
+import string
+import sys
+
+translate = str.maketrans('', '', string.punctuation)
+
+word_count = {}
+input_file = sys.argv[1]
+text = open(input_file).read()
+
+words = text.split()
+for word in words:
+ word = word.translate(translate).lower()
+ count = word_count.get(word, 0)
+ count += 1
+ word_count[word] = count
+rank = 1
+out_file = sys.argv[2]
+word_count_list = sorted(word_count, key=word_count.get, reverse=True)
+file_out = open(out_file, 'w')
+writer = csv.writer(file_out)
+for word in word_count_list:
+ writer.writerow([word, word_count[word], rank])
+ rank += 1