Initial commit
This commit is contained in:
		
						commit
						3c7ee303a4
					
				
							
								
								
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | |||
| venv/ | ||||
| *.pyc | ||||
| __pycache__/ | ||||
| 
 | ||||
							
								
								
									
										43
									
								
								csv2ankicards.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								csv2ankicards.py
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,43 @@ | |||
| import csv | ||||
| import genanki | ||||
| import sys | ||||
| 
 | ||||
| # Create a new model for our cards. This is necessary for genanki. | ||||
| MY_MODEL = genanki.Model( | ||||
|     1607392319, | ||||
|     "Simple Model", | ||||
|     fields=[ | ||||
|         {"name": "Question"}, | ||||
|         {"name": "Answer"}, | ||||
|     ], | ||||
|     templates=[ | ||||
|         { | ||||
|             "name": "Card 1", | ||||
|             "qfmt": "{{Question}}", | ||||
|             "afmt": "{{FrontSide}}<hr id='answer'>{{Answer}}", | ||||
|         }, | ||||
|     ]) | ||||
| 
 | ||||
| def csv_to_anki(csv_path, output_path): | ||||
|     with open(csv_path, 'r', encoding='utf-8') as f: | ||||
|         reader = csv.reader(f) | ||||
|         my_deck = genanki.Deck(2059400110, "CSV Deck") | ||||
|         for row in reader: | ||||
|             question, answer = row | ||||
|             note = genanki.Note( | ||||
|                 model=MY_MODEL, | ||||
|                 fields=[question, answer] | ||||
|             ) | ||||
|             my_deck.add_note(note) | ||||
|     genanki.Package(my_deck).write_to_file(output_path) | ||||
| 
 | ||||
| if __name__ == "__main__": | ||||
|     if len(sys.argv) != 3: | ||||
|         print("Usage: python convert.py <input_csv> <output_apkg>") | ||||
|         sys.exit(1) | ||||
|      | ||||
|     input_csv = sys.argv[1] | ||||
|     output_apkg = sys.argv[2] | ||||
|     csv_to_anki(input_csv, output_apkg) | ||||
|     print(f"Deck created at: {output_apkg}") | ||||
| 
 | ||||
							
								
								
									
										1
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1 @@ | |||
| genanki==0.8.0 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user