Skip to content

Instantly share code, notes, and snippets.

@theSage21
Created February 1, 2018 07:29
Show Gist options
  • Save theSage21/5c73da683be8751e19e8558c75c64638 to your computer and use it in GitHub Desktop.
Save theSage21/5c73da683be8751e19e8558c75c64638 to your computer and use it in GitHub Desktop.
Rajasthan Anganwadi content creater
wget https://drive.google.com/file/d/1M8kRWh-pt-CiSXtXSMX68YTwB7ibCB4C/view?usp=sharing -O small.zip
unzip small.zip
rm -rf uploads
cp -r Anganwadi-upload uploads
cd uploads
mv 'pdf/activity bank' 'Activity Bank'
mv 'pdf/activity book' 'Activity Book'
mv 'pdf/Child Assesment Card' 'Child Assessment Card'
mv 'pdf/curriculam' 'Curriculum'
mv 'pdf/syllabus' 'Syllabus'
mv 'pdf/traiing' 'Training'
mv 'pdf/tt' 'TT'
mv 'pro content/english/English varnmala v1' 'English Varnmala'
mv 'pro content/hindi/Hindi varnmala_ V1 new' 'Hindi Varnmala'
mv 'video' 'Videos'
rm -rf 'pdf' 'pro content' 'anganwadi_library_content.xls'
python push_folder.py
import os
import random
import requests
# root = 'https://rajasthan-aanganwadi.herokuapp.com'
root = 'http://localhost:8000'
def hit(api, json):
url = root + '/' + api.lstrip('/')
resp = requests.post(url, json=json)
return resp
print('Logging in admin')
admin = {'email': 'arjoonn.94@gmail.com',
'pwd': '2328904461', 'token': '1'*100}
assert hit('/user/login', json=admin).status_code == 200
print('Done')
# ###############################FORMS #######################
def makecat(id, title, contains, parent=None):
d = {"id": id, "title": title, "contains": contains,
"token": admin['token']}
if parent is not None:
d['parent'] = parent
r = hit("/category/create", d)
assert r.status_code == 200, r.text
def walk(name, pid):
print('Exploring', name)
present = list(sorted(os.listdir(name), reverse=True))
for i in present:
filename = os.path.join(name, i)
print(filename, end=' ')
if os.path.isdir(filename):
id = '_' + ''.join([random.choice('0123456789')
for _ in range(100)])
makecat(id, i, [], pid)
walkpath = os.path.join(name, i)
walk(walkpath, id)
print('DIR')
else:
print('FIL')
if '.wav' in i:
os.system("cp '{}' input.wav".format(filename))
os.system("yes | ffmpeg -i input.wav -vn -ar 44100 -ac 2 -ab 192k -f mp3 output.mp3")
filename = 'output.mp3'
if not any([ext in i for ext in ['png', 'mp4']]):
with open(filename, 'rb') as fl:
files = {'upload': (i, fl)}
values = {'token': admin['token'],
"title": i,
"desc": "Sample file for demo" + i,
"parent": pid}
r = requests.post(root + '/content/create',
files=files,
data=values)
assert r.status_code == 200
makecat("_ROOT_", "Home", [])
walk("uploads", "_ROOT_")
print('Logging out')
assert hit('/user/logout', json=admin).status_code == 200
print('Done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment