Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added autogen.py #17

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions autogen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""
This script generates .txt from the secrets/Contacts repo.
The name of the .txt file will be the same as that of the .csv file used.
Please provide the path to the Contacts folder while running the script.
e.g: python autogen.py ../secrets/Contacts/
(The last '/' is mandatory.)
Note: Latest year = freshers, latest - 1 = executives,
<latest - 2 = seniors, hyphen joined filename = Alumni
"""

import os
import os.path
import sys
import glob

pathname = sys.argv[1]
filelist = glob.glob(pathname + "*.csv")

namemap = dict()
yearlist = list()

for csv in filelist:
f = os.path.basename(csv)[:-4]
if '-' in f:
"""
Many old year members punched into one file.
Must be our respected alumni.
"""
namemap[f] = "alumni"
else:
yearlist.append(int(f))

yearlist.sort()
namemap[str(yearlist[-1])] = "freshers"
namemap[str(yearlist[-2])] = "executives"
for i in yearlist[:-2]:
namemap[str(i)] = "seniors"


for csv in filelist:
f = open(csv, "r")
w = open(namemap[os.path.basename(csv)[:-4]] + ".txt", "w")

f.readline()
for line in f.readlines():
handle = line.split(",")[5]
handle = handle.strip()
handle = handle.split("/")[0]
w.write(handle+'\n')

print ".txt files generated!. Do you want to run json_maker.py and main.py?"
choice = str(raw_input(" [y/n] "))

if choice == "y":
os.system("python json_maker.py")
os.system("python main.py")
elif choice == "n":
print "Bye!"
else:
print "Unknown choice entered! Aborting"

print "\n"
51 changes: 1 addition & 50 deletions data.json
Original file line number Diff line number Diff line change
@@ -1,50 +1 @@
{
"freshers": [
"jsadhi05",
"amritashbharadwaj",
"ankita13",
"rava-dosa",
"aribis369",
"aryan",
"ashishkg",
"obitors",
"chelsi",
"dj.barnwal",
"dibyadas",
"hn2907",
"kev6808",
"tibrewalpratik17",
"vernwalrahul",
"roshni",
"sachin.uttarwar007",
"samruddhi",
"rishukid",
"americast",
"shaildaswani",
"deadshourya",
"sipah00"
],
"seniors": [
"gauravrpjain",
"bad-smruti",
"orkohunter",
"avijit",
"kshitij10496",
"mayank-kgp",
"pr4nay",
"rik",
"nishnik",
"anomaly_",
"defcon",
"madan96",
"parthvader",
"pungi-man",
"shubham5",
"saksham0037",
"shikha",
"pratham_pc",
"minato",
"tormenta",
"mr-yamraj"
]
}
{}