CSV export file manipulations
for i in word_db:
print(i)
Google drive creates problem when generated shared links if there are more than 3500 files in a folder.
So, I am copying media files to folders.
path = r'C:\Users\Gyan Tatiya\AppData\Roaming\Anki2\User 2\collection.media'
if not os.path.exists(path + os.sep + 'Word audio2'):
os.makedirs(path + os.sep + 'Word audio2')
if not os.path.exists(path + os.sep + 'Picture2'):
os.makedirs(path + os.sep + 'Picture2')
if not os.path.exists(path + os.sep + 'Note Image'):
os.makedirs(path + os.sep + 'Note Image')
if not os.path.exists(path + os.sep + 'Multimedia Example2'):
os.makedirs(path + os.sep + 'Multimedia Example2')
for i in word_db:
for IMA_file in i['Word audio2']:
shutil.copy(path + os.sep + IMA_file, path + os.sep + 'Word audio2')
for IMA_file in i['Picture2']:
shutil.copy(path + os.sep + IMA_file, path + os.sep + 'Picture2')
for IMA_file in i['Note Image']:
shutil.copy(path + os.sep + IMA_file, path + os.sep + 'Note Image')
for IMA_file in i['Multimedia Example2']:
shutil.copy(path + os.sep + IMA_file, path + os.sep + 'Multimedia Example2')
Upload files
Go to google drive and upload the 4 generated folder.
Generate csv files that has shared links, and remane: FlashVocab_sheet - Multimedia Example2.csv, FlashVocab_sheet - Note Image.csv, FlashVocab_sheet - Picture2.csv, FlashVocab_sheet - Word audio2.csv
with open(folder + os.sep + 'FlashVocab_sheet - Multimedia Example2.csv', mode='r') as infile:
reader = csv.reader(infile)
mul_dict = {}
for i in reader:
mul_dict[i[1]] = i[3]
#print(mul_dict)
with open(folder + os.sep + 'FlashVocab_sheet - Note Image.csv', mode='r') as infile:
reader = csv.reader(infile)
not_dict = {}
for i in reader:
not_dict[i[1]] = i[3]
#print(not_dict)
with open(folder + os.sep + 'FlashVocab_sheet - Picture2.csv', mode='r') as infile:
reader = csv.reader(infile)
pic_dict = {}
for i in reader:
pic_dict[i[1]] = i[3]
#print(pic_dict)
with open(folder + os.sep + 'FlashVocab_sheet - Word audio2.csv', mode='r') as infile:
reader = csv.reader(infile)
aud_dict = {}
for i in reader:
aud_dict[i[1]] = i[3]
#print(aud_dict)
"""
Updating word_db by inserting shared links
"""
for i in range(len(word_db)):
links = []
for IMA_file in word_db[i]['Word audio2']:
link = aud_dict[IMA_file]
links.append(link)
word_db[i]['Word audio2 links'] = links
links = []
for IMA_file in word_db[i]['Picture2']:
link = pic_dict[IMA_file]
links.append(link)
word_db[i]['Picture2 links'] = links
links = []
for IMA_file in word_db[i]['Note Image']:
link = not_dict[IMA_file]
links.append(link)
word_db[i]['Note Image links'] = links
links = []
for IMA_file in word_db[i]['Multimedia Example2']:
link = mul_dict[IMA_file]
links.append(link)
word_db[i]['Multimedia Example2 links'] = links
"""
Writes out the generated word_db
"""
with open(folder + os.sep + 'word_db_links.csv','wb') as f:
w = csv.writer(f)
w.writerow(word_db[0].keys()) # keys in top row
for i in word_db:
w.writerow(i.values())
"""
Updating word_db by inserting export shared links
https://drive.google.com/uc?export=view&id={fileId}
"""
for i in range(len(word_db)):
links = []
for IMA_file in word_db[i]['Word audio2 links']:
file_id = IMA_file.split('/')[5]
export_link = 'https://drive.google.com/uc?export=view&id=' + file_id
links.append(export_link)
word_db[i]['Word audio2 export links'] = links
links = []
for IMA_file in word_db[i]['Picture2 links']:
file_id = IMA_file.split('/')[5]
export_link = 'https://drive.google.com/uc?export=view&id=' + file_id
links.append(export_link)
word_db[i]['Picture2 export links'] = links
links = []
for IMA_file in word_db[i]['Note Image links']:
file_id = IMA_file.split('/')[5]
export_link = 'https://drive.google.com/uc?export=view&id=' + file_id
links.append(export_link)
word_db[i]['Note Image export links'] = links
links = []
for IMA_file in word_db[i]['Multimedia Example2 links']:
file_id = IMA_file.split('/')[5]
export_link = 'https://drive.google.com/uc?export=view&id=' + file_id
links.append(export_link)
word_db[i]['Multimedia Example2 export links'] = links
"""
Writes out the generated word_db
"""
with open(folder + os.sep + 'word_db_links_export.csv','wb') as f:
w = csv.writer(f)
w.writerow(word_db[0].keys()) # keys in top row
for i in word_db:
w.writerow(i.values())
sort_dict_column(folder + os.sep + 'word_db_links_export_gre_sorted.csv', word_gre_db)
"""
This it to be used in Words.java in MyWordDataDisplay project
"""
words_tem = word_gre_db
#words_tem = word_db
java_commands = open('java_commands.txt', 'w')
java_commands.close()
n = 0
for i in words_tem:
del i['Mnemonic'] # delete Mnemonic because it has '"' character
del i['Note'] # I am not going to use Note
del i['Note Image export links'] # I am not going to use Note
del i['Other form'] # I am not going to use Other form
del i['Picture'] # I am not going to use Picture
del i['Word audio2'] # I am not going to use
del i['Tags'] # I am not going to use
del i['Tags2'] # I am not going to use
del i['Picture2'] # I am not going to use
del i['Multimedia Example'] # I am not going to use
del i['Multimedia Example2 links'] # I am not going to use
del i['Note Image links'] # I am not going to use
del i['Word audio2 export links'] # I am not going to use
del i['Picture2 links'] # I am not going to use
del i['Multimedia Example2 export links'] # I am not going to use
del i['Note Image'] # I am not going to use
del i['Word audio'] # I am not going to use
del i['Word audio2 links'] # I am not going to use
del i['Multimedia Example2'] # I am not going to use
java_commands = open('java_commands.txt', 'a') # append to the file created
java_commands.write("Map map"+str(n)+ " = new HashMap();" + '\n')
for k, v in i.items():
java_commands.write("map"+str(n)+ ".put(\""+str(k)+"\""+", \""+str(v)+"\""+");" + '\n')
java_commands.write("maps.add(map"+str(n)+ ");" + '\n')
n += 1
java_commands.close()
"""
This it to be used in word_db.txt in MyWordDataDisplay project
"""
words_tem = word_gre_db
#words_tem = word_db
java_commands = open('java_commands.txt', 'w')
java_commands.close()
#n = 0
for i in words_tem:
del i['Mnemonic'] # delete Mnemonic because it has '"' character
del i['Note'] # I am not going to use Note
del i['Note Image export links'] # I am not going to use Note
del i['Other form'] # I am not going to use Other form
del i['Picture'] # I am not going to use Picture
del i['Word audio2'] # I am not going to use
del i['Tags'] # I am not going to use
del i['Tags2'] # I am not going to use
del i['Picture2'] # I am not going to use
del i['Multimedia Example'] # I am not going to use
del i['Multimedia Example2 links'] # I am not going to use
del i['Note Image links'] # I am not going to use
del i['Word audio2 export links'] # I am not going to use
del i['Picture2 links'] # I am not going to use
del i['Multimedia Example2 export links'] # I am not going to use
del i['Note Image'] # I am not going to use
del i['Word audio'] # I am not going to use
del i['Word audio2 links'] # I am not going to use
del i['Multimedia Example2'] # I am not going to use
java_commands = open('java_commands.txt', 'a') # append to the file created
#java_commands.write("Map map"+str(n)+ " = new HashMap();" + '\n')
for k, v in i.items():
java_commands.write(str(v)+'\n')
#java_commands.write("maps.add(map"+str(n)+ ");" + '\n')
#n += 1
java_commands.close()