-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathupload_to_ia.py
executable file
·78 lines (51 loc) · 2.32 KB
/
upload_to_ia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import string
import yaml
import os
import re
import sys
import time
import glob
book_info = yaml.full_load(open('book-info.yaml'))
book_title = book_info['book_title']
book_title_in_english = book_info['book_title_in_english'].replace(" ","_").replace("-","_")
cover_image = book_info['cover_image']
epubfile = book_title_in_english + ".epub"
mobifile = book_title_in_english + ".mobi"
a4_pdf = book_title_in_english + "_a4.pdf"
six_inch_file = book_title_in_english + "_6_inch.pdf"
if os.path.isfile(epubfile) == False:
print("File name error in epub file. Change as " + epubfile)
sys.exit()
if os.path.isfile(mobifile) == False:
print("File name error in mobi file. Change as " + mobifile)
sys.exit()
if os.path.isfile(a4_pdf) == False:
print("File name error in A4 PDF file. Change as " + a4_pdf)
sys.exit()
if os.path.isfile(six_inch_file) == False:
print("File name error in 6 inch PDF file. Change as " + six_inch_file)
sys.exit()
if os.path.isfile(cover_image) == False:
print("File name error in Cover Image. Change as " + cover_image)
sys.exit()
os.mkdir(book_title_in_english + "-upload")
os.system("mv *pdf *odt *doc *docx *epub *mobi *jpg *png *JPG *PNG " + book_title_in_english + "-upload 2>/dev/null" )
os.system("cp *.yaml " + book_title_in_english + "-upload" )
os.system("cp *.conf " + book_title_in_english + "-upload" )
timestamp = time.strftime('%Y-%m-%d-%H-%M-%S')
ia_identifier = book_title_in_english + "-" + timestamp
content_dir = book_title_in_english + "-upload/"
ia_upload = "ia upload " + ia_identifier + \
" -m collection:opensource -m mediatype:texts -m sponsor:FreeTamilEbooks -m language:tam "
all_files = glob.glob(content_dir + "*")
for afile in all_files:
ia_upload = ia_upload + "'" + afile + "'" + " "
ia_upload = "ia upload " + ia_identifier + \
" -m collection:opensource -m mediatype:texts -m sponsor:FreeTamilEbooks -m language:tam " + \
content_dir + book_title_in_english + ".epub " + content_dir + book_title_in_english + ".mobi " +\
content_dir + book_title_in_english + "_a4.pdf " + content_dir + book_title_in_english + "_6_inch.pdf " + \
content_dir + cover_image + " " + "book-info.yaml" + " _rules.conf"
print("Uploading to Internet Archive")
print(ia_upload)
os.system(ia_upload)
print("Uploaded to https://archive.org/details/" + ia_identifier)