-
Notifications
You must be signed in to change notification settings - Fork 3
/
publish-to-fte-chrome.py
executable file
·953 lines (647 loc) · 29.4 KB
/
publish-to-fte-chrome.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from wordpress_xmlrpc import WordPressPost
from wordpress_xmlrpc import Client
from wordpress_xmlrpc.methods import posts,media
from wordpress_xmlrpc.methods.posts import NewPost
from wordpress_xmlrpc.compat import xmlrpc_client
from wordpress_xmlrpc.methods import taxonomies
from xmlrpc.client import SafeTransport
from urllib.request import urlopen
import urllib
import shutil
import unittest, time, re
import os
import re
import yaml
import sys
import time
import uuid
import shutil
import json
import argparse
import requests
import base64
from github import Github
from mastodon import Mastodon
#from mailjet_rest import Client
import mailjet_rest
#https://www.zenrows.com/blog/selenium-cloudflare-bypass#cloudflare-bypass-using-zenrows
#import undetected_chromedriver as uc
parser = argparse.ArgumentParser()
parser.add_argument('-l','--local-file', help='Use Local File', required=False)
parser.add_argument('-r','--remote-book-url', help='Use Remote File', required=False)
parser.add_argument('-i','--interactive', help='Interactive Mode', required=False)
parser.add_argument('-bn','--book_number', help='Book Number', required=True)
parser.add_argument('-issue','--github_issue_number',help = "Github Issue number", required=False)
parser.add_argument('-epub','--epub-id',help = "epub id", required=False)
parser.add_argument('-mobi','--mobi-id',help = "mobi id", required=False)
parser.add_argument('-a4_pdf','--a4-pdf-id',help = "A4 PDF id", required=False)
parser.add_argument('-sixinch_pdf','--six-inch-pdf-id',help = "6 inch PDF id", required=False)
args = parser.parse_args()
local_file = args.local_file
remote_book_url = args.remote_book_url
interactive = args.interactive
book_number = args.book_number
github_issue_number = int(args.github_issue_number)
epub_id = args.epub_id
mobi_id = args.mobi_id
a4_id = args.a4_pdf_id
sixinch_id = args.six_inch_pdf_id
home = os.getenv("HOME")
fte_yaml = yaml.full_load(open(home + '/.config/fte-login.yaml'))
fte_username = fte_yaml['username']
fte_password = fte_yaml['password']
git_username = fte_yaml['git_username']
git_password = fte_yaml['git_password']
android_push_Authorization = fte_yaml['android_push_Authorization']
mastodon_access_token = fte_yaml['mastodon_access_token']
mastodon_url = fte_yaml['mastodon_url']
mailjet_api_key = fte_yaml['mailjet_api_key']
mailjet_api_secret = fte_yaml['mailjet_api_secret']
telegram_token = fte_yaml['telegram_token']
telegram_channel_chat_id = fte_yaml['telegram_channel_chat_id']
class SpecialTransport(SafeTransport):
user_agent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0'
wp = Client('https://freetamilebooks.com/xmlrpc.php', fte_username, fte_password, transport=SpecialTransport())
post = WordPressPost()
#print("Try after one hour")
#sys.exit()
def send_image_to_telegram(image):
img = open(image,'rb')
api_url = f'https://api.telegram.org/bot{telegram_token}/sendPhoto?chat_id={telegram_channel_chat_id}'
try:
response = (requests.post(api_url, files={'photo': img}))
print(response.text)
except Exception as e:
print(e)
'''
print(image)
print(telegram_token)
print(telegram_channel_chat_id)
apiURL = f'https://api.telegram.org/bot{telegram_token}/sendPhoto'
print(apiURL)
try:
response = requests.post(apiURL, json={'chat_id': telegram_channel_chat_id, 'photo': image})
print(response.text)
except Exception as e:
print(e)
'''
def send_text_to_telegram(message):
apiURL = f'https://api.telegram.org/bot{telegram_token}/sendMessage'
try:
response = requests.post(apiURL, json={'chat_id': telegram_channel_chat_id, 'text': message})
print(response.text)
except Exception as e:
print(e)
if remote_book_url:
book_url = remote_book_url
print("Getting Book Info")
book_info = yaml.full_load(urlopen(book_url.replace('details','download') + '/book-info.yaml'))
book_title = book_info['book_title']
print(book_title)
book_title_in_english = book_info['book_title_in_english'].replace(" ","_").replace("-","_")
author = book_info['author']
print(author)
category = book_info['category']
print(category)
if book_info['author_mail']:
author_mail = book_info['author_mail']
else:
author_mail = ""
cover_image = book_info['cover_image']
if book_info['artist']:
artist = book_info['artist']
else:
artist = ""
if book_info['artist_email']:
artist_email = book_info['artist_email']
else:
artist_email = ""
if book_info['translator']:
translator = book_info['translator']
else:
translator = ""
if book_info['translator_email']:
translator_email = book_info['translator_email']
else:
translator_email = ""
if 'author_communication' in book_info:
if book_info['author_communication']:
author_communication = book_info['author_communication']
else:
author_communication = ""
else:
author_communication = ""
if 'author_communication_email' in book_info:
if book_info['author_communication_email']:
author_communication_email = book_info['author_communication_email']
else:
author_communication_email = ""
else:
author_communication_email = ""
if 'ocr_proofread' in book_info:
if book_info['ocr_proofread']:
ocr_proofread = book_info['ocr_proofread']
else:
ocr_proofread = ""
else:
ocr_proofread = ""
if 'ocr_proofread_email' in book_info:
if book_info['ocr_proofread_email']:
ocr_proofread_email = book_info['ocr_proofread_email']
else:
ocr_proofread_email = ""
else:
ocr_proofread_email = ""
ebook_maker = book_info['ebook_maker']
ebook_maker_email = book_info['ebook_maker_email']
license = book_info['license']
epub_url = book_url.replace('details','download') + "/" + book_title_in_english + ".epub"
mobi_url = book_url.replace('details','download') + "/" + book_title_in_english + ".mobi"
a4_pdf_url = book_url.replace('details','download') + "/" + book_title_in_english + "_a4.pdf"
six_inch_pdf_url = book_url.replace('details','download') + "/" + book_title_in_english + "_6_inch.pdf"
cover_url = book_url.replace('details','download') + "/" + cover_image
if interactive == "yes":
book_title = input("Book Title : ").strip()
book_title_in_english = input("Book Title in English : ").strip()
book_url = input("Book Archive URL : ").strip()
author = input("Author : ").strip()
author_mail = input("Author Mail : ").strip()
artist = input("Artist : ").strip()
artist_email = input("Artist Email : ").strip()
translator = input("Translator : ").strip()
translator_email = input("Translator Email : ").strip()
ebook_maker = input("Ebook made by : ").strip()
ebook_maker_email = input("Ebook Maker email : ").strip()
license = input("License : ").strip()
category = input("category : ").strip()
cover_url = input("Cover Image URL : ").strip()
epub_url = input("Epub URL : ").strip()
mobi_url = input("Mobi URL : ").strip()
a4_pdf_url = input("A4 PDF URL : ").strip()
six_inch_pdf_url = input("Six inch PDF URL : ")
cover_image = book_title_in_english + "_cover.jpg"
print("Logging in to FreeTamilEbooks.com")
#binary = FirefoxBinary('/home/shrinivasan/firefox/firefox')
#driver = webdriver.Firefox(firefox_binary=binary)
'''
options = Options()
# options.headless = True # older webdriver versions
#options.set_headless(True) # newer webdriver versions
#options.add_argument("--headless")
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("-profile")
# put the root directory your default profile path here, you can check it by opening Firefox and then pasting 'about:profiles' into the url field
#options.add_argument("/home/shrini/snap/firefox/common/.mozilla/firefox/sjfdcwiq.default")
options.add_argument("/home/shrini/snap/firefox/common/.mozilla/firefox/518ao2wl.default")
service = Service(executable_path="./geckodriver")
driver = webdriver.Firefox(options=options, service=service)
'''
#options = webdriver.ChromeOptions()
#options.add_argument('ignore-certificate-errors')
#options.add_argument('--ignore-ssl-errors=yes')
#options.add_argument("--disable-blink-features=AutomationControlled")
#options.add_argument("--no-sandbox");
#options.add_argument("--disable-dev-shm-usage");
#driver = webdriver.Chrome(options=options)
driver = webdriver.Chrome('./chromedriver') # Optional argument, if not specified will search path.
'''
options = uc.ChromeOptions()
options.headless = False # Set headless to False to run in non-headless mode
driver = uc.Chrome(use_subprocess=True, options=options)
'''
#driver = webdriver.Firefox(options=options,executable_path=r'./geckodriver')
#driver = webdriver.Firefox(executable_path=r'./geckodriver')
driver.implicitly_wait(5)
driver.maximize_window()
base_url = "https://freetamilebooks.com"
verificationErrors = []
accept_next_alert = True
driver.get("https://freetamilebooks.com/wp-admin")
driver.implicitly_wait(10)
time.sleep(10)
# driver.find_element_by_link_text("Log in with username and password").click()
driver.find_element(By.ID,"user_pass").clear()
driver.find_element(By.ID,"user_pass").send_keys(fte_password)
driver.find_element(By.ID,"user_login").clear()
driver.find_element(By.ID,"user_login").send_keys(fte_username)
driver.find_element(By.ID,"wp-submit").click()
# driver.find_element_by_link_text("Download").click()
driver.implicitly_wait(20)
def add_download(filename,file_url):
driver.get("https://freetamilebooks.com/wp-admin/post-new.php?post_type=dlm_download")
driver.find_element(By.ID,"title").clear()
driver.find_element(By.ID,"title").send_keys(filename)
time.sleep(20)
# driver.find_element_by_xpath("//*[@id='download-monitor-file']").click()
# driver.find_element(by=By.XPATH, value='.//*[@id="download-monitor-file"]').click()
'''
driver.find_element(By.CSS_SELECTOR, "#download-monitor-file .hndle").click()
time.sleep(10)
driver.find_element(By.LINK_TEXT, "Custom URL").click()
time.sleep(10)
# 9 | mouseOver | linkText=Custom URL |
element = driver.find_element(By.LINK_TEXT, "Custom URL")
time.sleep(10)
actions = ActionChains(driver)
actions.move_to_element(element).perform()
# 10 | mouseOut | linkText=Custom URL |
element = driver.find_element(By.CSS_SELECTOR, "body")
actions = ActionChains(driver)
actions.move_to_element(element, 0, 0).perform()
# 11 | click | name=downloadable_file_urls[0] |
driver.find_element(By.NAME, "downloadable_file_urls[0]").click()
# 12 | type | name=downloadable_file_urls[0] | a
driver.find_element(By.NAME, "downloadable_file_urls[0]").send_keys(file_url)
time.sleep(10)
# 13 | click | id=publish |
driver.find_element(By.ID, "publish").click()
time.sleep(5)
'''
# print("clicked expand")
# driver.find_element(By.CSS_SELECTOR, "#download-monitor-file .hndle").click()
time.sleep(10)
# driver.find_element(by=By.XPATH, value='.//*[@id="drag-drop-area"]/div[1]/p[4]/a[3]').click()
# driver.implicitly_wait(30)
# time.sleep(20)
# driver.find_element_by_xpath(".//*[@class='downloadable_file_urls']").click()
print("clicking the url button")
driver.find_element(By.CLASS_NAME, "dlm_external_source").click()
time.sleep(20)
driver.find_element(by=By.XPATH, value='.//*[@id="__wp-uploader-id-2"]/textarea').send_keys(file_url)
# driver.implicitly_wait(30)
driver.execute_script("window.scrollTo(0,0)")
# element = driver.find_element(By.CSS_SELECTOR, "body")
# actions = ActionChains(driver)
# actions.move_to_element(element, 0, 0).perform()
time.sleep(20)
driver.find_element(By.ID, "publish").click()
# driver.find_element(by=By.XPATH, value='.//*[@id="publish"]').click()
# publish_button = WebDriverWait(driver, 40).until(
# EC.presence_of_element_located((By.XPATH, ".//*[@id='publish']"))
# )
# publish_button.click()
# driver.find_element_by_xpath(".//*[@id='publish']").click()
# driver.implicitly_wait(30)
time.sleep(20)
dl_text = WebDriverWait(driver, 40).until(
EC.presence_of_element_located((By.ID, "dlm-info-id"))
)
dl_id = dl_text.get_attribute('value')
# dl_id = driver.find_element_by_id('dlm-info-id').get_attribute('value')
# driver.implicitly_wait(30)
time.sleep(20)
# dl_url = driver.find_element_by_id('dlm-info-url').get_attribute('value')
dl_url = driver.find_element_by_css_selector('.dlm_information_panel > div:nth-child(2) > input:nth-child(2)').get_attribute('value')
print("Adding " + filename)
return(dl_id,dl_url)
print("Adding Downloads")
if epub_id:
epub_data = []
epub_data.append(epub_id)
driver.get("https://freetamilebooks.com/wp-admin/post.php?post="+epub_id+"&action=edit")
time.sleep(10)
# dl_url = driver.find_element_by_id('dlm-info-url').get_attribute('value')
dl_url = driver.find_element_by_css_selector('.dlm_information_panel > div:nth-child(2) > input:nth-child(2)').get_attribute('value')
epub_data.append(dl_url)
else:
epub_data = add_download(book_title + " epub",epub_url )
if mobi_id:
mobi_data = []
mobi_data.append(mobi_id)
driver.get("https://freetamilebooks.com/wp-admin/post.php?post="+mobi_id+"&action=edit")
time.sleep(10)
# dl_url = driver.find_element_by_id('dlm-info-url').get_attribute('value')
dl_url = driver.find_element_by_css_selector('.dlm_information_panel > div:nth-child(2) > input:nth-child(2)').get_attribute('value')
mobi_data.append(dl_url)
else:
mobi_data = add_download(book_title + " mobi",mobi_url)
if a4_id:
a4_pdf_data = []
a4_pdf_data.append(a4_id)
driver.get("https://freetamilebooks.com/wp-admin/post.php?post="+a4_id+"&action=edit")
time.sleep(10)
# dl_url = driver.find_element_by_id('dlm-info-url').get_attribute('value')
dl_url = driver.find_element_by_css_selector('.dlm_information_panel > div:nth-child(2) > input:nth-child(2)').get_attribute('value')
a4_pdf_data.append(dl_url)
else:
a4_pdf_data = add_download(book_title + " A4 PDF",a4_pdf_url)
if sixinch_id:
six_inch_pdf_data=[]
six_inch_pdf_data.append(sixinch_id)
driver.get("https://freetamilebooks.com/wp-admin/post.php?post="+sixinch_id+"&action=edit")
time.sleep(10)
# dl_url = driver.find_element_by_id('dlm-info-url').get_attribute('value')
dl_url = driver.find_element_by_css_selector('.dlm_information_panel > div:nth-child(2) > input:nth-child(2)').get_attribute('value')
six_inch_pdf_data.append(dl_url)
else:
six_inch_pdf_data = add_download(book_title + " 6 inch PDF",six_inch_pdf_url)
driver.quit()
#epub_data = (1,"a")
#mobi_data = (1,"a")
#a4_pdf_data = (1,"a")
#six_inch_pdf_data = (1,"a")
#print(book_title_in_english)
#For security, consider creating a user just for your script.
'''
url = "https://freetamilebooks.com/wp-json/wp/v2"
credentials = fte_username + ':' + fte_password
token = base64.b64encode(credentials.encode())
headers = {'Authorization': 'Basic ' + token.decode('utf-8')}
'''
class SpecialTransport(SafeTransport):
user_agent = 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0'
wp = Client('https://freetamilebooks.com/xmlrpc.php', fte_username, fte_password, transport=SpecialTransport())
post = WordPressPost()
taxes = wp.call(taxonomies.GetTaxonomies())
#print(taxes)
with urllib.request.urlopen(cover_url) as response, open(cover_image, 'wb') as out_file:
shutil.copyfileobj(response, out_file)
#print("Downloaded Cover Image")
filename = cover_image
'''
image = {
"file": open(filename, "rb"),
"caption": "caption",
"description": "description",
}
print(image)
print(headers)
print(url + "/media")
response = requests.post(url + "/media", headers=headers, files=image)
'''
data = {
'name': filename,
'type': 'image/jpeg', # mimetype
}
# read the binary file and let the XMLRPC library encode it into base64
with open(filename, 'rb') as img:
data['bits'] = xmlrpc_client.Binary(img.read())
response = wp.call(media.UploadFile(data))
#print(response)
image_url = response["url"]
attachment_id = response['id']
#print("Uploaded cover Image")
#medium_image_width = str(response["media_details"]["sizes"]["medium"]["width"])
#medium_image_height = str(response["media_details"]["sizes"]["medium"]["height"])
#medium_image_url = image_url.replace('.jpg','-' + str(medium_image_width) +'x' + str(medium_image_height) + '.jpg')
#medium_image_url = str(response["media_details"]["sizes"]["medium"]["source_url"])
medium_image_width = str(response["metadata"]["sizes"]["medium"]["width"])
medium_image_height = str(response["metadata"]["sizes"]["medium"]["height"])
medium_image_url = image_url.replace('.jpg','-' + str(medium_image_width) +'x' + str(medium_image_height) + '.jpg')
content = "நூல் : " + book_title + "\n\n" + "ஆசிரியர் : " + author + "\n<a href=" + image_url + "><img class='alignright size-medium wp-image-6958' src=" + medium_image_url + " width='" + medium_image_width + "' height='" + medium_image_height +"' /></a>" + "\n"
print("Generating Content to Post")
if author_mail :
content = content + "மின்னஞ்சல் : " + author_mail + "\n\n\n"
if artist:
content = content + "அட்டைப்படம் : " + artist + "\n\n"
if artist_email:
content = content + artist_email + "\n\n"
if translator:
content = content + "தமிழாக்கம் : " + translator + "\n\n"
if translator_email:
content = content + translator_email + "\n\n"
if ebook_maker:
content = content + "மின்னூலாக்கம் : " + ebook_maker + "\n"
if ebook_maker_email:
content = content + "மின்னஞ்சல் : " + ebook_maker_email + "\n\n"
if author_communication:
content = content + "நூல் ஆசிரியர் தொடர்பாளர் : " + author_communication + "\n"
if author_communication_email:
content = content + "நூல் ஆசிரியர் தொடர்பாளர் மின்னஞ்சல் : " + author_communication_email + "\n\n"
if ocr_proofread:
content = content + "எழுத்துணரி, மெய்ப்பாளர் : " + ocr_proofread + "\n"
if ocr_proofread_email:
content = content + "எழுத்துணரி, மெய்ப்பாளர் மின்னஞ்சல் : " + ocr_proofread_email + "\n\n"
content = content + "வெளியிடு : FreeTamilEbooks.com" + "\n\n"
content = content + "உரிமை : " + license + "\n\n" + "உரிமை – கிரியேட்டிவ் காமன்ஸ். எல்லாரும் படிக்கலாம், பகிரலாம்." + "\n"
extra = '''
<b>பதிவிறக்க*</b>
ஆன்ட்ராய்டு(FBreader), ஆப்பிள், புது நூக் கருவிகளில் படிக்க
[download id=" ''' + str(epub_data[0]) + '''" template="button"]
புது கிண்டில் கருவிகளில் படிக்க
[download id=" ''' + str(mobi_data[0]) + '''" template="button"]
குனூ/லினக்ஸ், விண்டோஸ் கணிணிகளில் படிக்க
[download id=" ''' + str(a4_pdf_data[0]) + '''" template="button"]
பழைய கிண்டில்,நூக் கருவிகளில் படிக்க
[download id=" ''' + str(six_inch_pdf_data[0]) + '''" template="button"]
<a>Send To Kindle Directly</a><a href="http://35.166.185.40/send2kindle?fileurl=''' + str(mobi_data[1]) + '''&filename=''' +book_title_in_english + '''.mobi" target="_blank" rel="noopener"><img class="alignleft wp-image-6127 " src="https://freetamilebooks.com/wp-content/uploads/2017/09/send-to-kindle-logo.jpg" alt="" width="579" height="129" /></a>
பிற வடிவங்களில் படிக்க – ''' + book_url + '''
புத்தக எண் - ''' + str(book_number) + '''
'''
print("Publising the Ebook")
content = content + extra
'''
postDict = {
"title": book_title + " - " + category + " - " + author ,
"content": content,
"slug": book_title_in_english,
"status": "publish",
"categories": categoryIdList, # [1374]
"tags": tagIdList, # [1367, 13224, 13225, 13226]
# TODO: featured_media, excerpt
}
'''
post.title = book_title + " - " + category + " - " + author
post.slug = book_title_in_english
post.post_type = 'ebooks'
post.content = content
post.thumbnail = attachment_id
post.comment_status = 'open'
post.post_status = 'publish'
#post.post_status = 'draft'
if artist:
post.terms_names = {
'genres': [category],
'contributors': [artist, ebook_maker],
'authors' : [author]
}
else:
post.terms_names = {
'genres': [category],
'contributors': [ebook_maker],
'authors' : [author]
}
wp.call(NewPost(post))
print("Published")
os.system("rm " + cover_image)
book_name = book_title
bookid = str(uuid.uuid4())
cover_image = image_url
gen = category
epub_link = epub_data[1]
authors = author
url = "https://freetamilebooks.com/ebooks/" + book_title_in_english
data = {}
data["title"] = book_name
data["bookid"] = bookid
data["author"] = author
data["image"] = cover_image
data["epub"] = epub_link
data["category"] = category
'''
xml_content = "\n\n" + "<book>" +"\n" + "<bookid>" + bookid + "</bookid>" + "\n" + "<title>" + book_name + "</title>" + "\n"
xml_content = xml_content + "<author>" + authors + "</author>" + "\n"
xml_content = xml_content + "<image>" + cover_image + "</image>" + "\n"
xml_content = xml_content + "<link>" + url + "</link>" + "\n"
xml_content = xml_content + "<epub>" + epub_link + "</epub>" + "\n"
xml_content = xml_content + "<pdf />" + "\n"
xml_content = xml_content + "<category>" + gen + "</category>" + "\n"
xml_content = xml_content + "<date />" + "\n" + "</book>" + "\n"
#print(xml_content)
'''
print("Adding into booksdb.json\n")
git_clone = "git clone https://" + git_username +":" + git_password + "@github.com/KaniyamFoundation/Free-Tamil-Ebooks fte_repo > git.log 2>&1"
os.system(git_clone)
'''
temp = open('temp', 'w')
with open('fte_repo/booksdb.json','r') as f:
for line in f:
if line.startswith('<books>'):
line = line + xml_content
temp.write(line)
temp.close()
shutil.move('temp', 'fte_repo/booksdb.xml')
'''
with open('fte_repo/booksdb.json') as f:
existing_data = json.load(f)
existing_data['books'].insert(0,data)
with open('fte_repo/booksdb.json', 'w') as f:
json.dump(existing_data,f,indent=2, sort_keys=False,ensure_ascii=False)
os.chdir('fte_repo')
git_add = "git add booksdb.json >> git.log 2>&1"
os.system(git_add)
git_commit = "git commit -m 'added a book' >> git.log 2>&1"
os.system(git_commit)
git_push = "git push origin master >> git.log 2>&1"
os.system(git_push)
os.chdir('../')
os.system("rm -rf fte_repo")
print("Done")
print("Sending Push Notification to Android Devices")
title = "புது மின்னூல் - " + book_title
text = "FreeTamilEbooks ன் புதிய மின்னூல் வெளியிடப்பட்டுள்ளது. " + book_title + " " + author + ". இன்றே படியுங்கள். "
headers = {'Authorization': android_push_Authorization}
headers = json.dumps(headers,ensure_ascii=False)
header_json = json.loads(headers)
data = {'notification':{'title': title, 'text': text }, 'data' : { 'keyname': 'shrini' },'to' : '/topics/fte_books'}
data = json.dumps(data,ensure_ascii=False)
data_json = json.loads(data)
api = "https://fcm.googleapis.com/fcm/send"
r = requests.post(api, json=data_json, headers=header_json)
#print(r.json())
mailjet = mailjet_rest.Client(auth=(mailjet_api_key, mailjet_api_secret), version='v3.1')
if len(artist_email.strip()) <2:
artist_email = "[email protected]"
if len(artist.strip()) <2:
artist = "Kaniyam Foundation"
if len(translator_email.strip()) <2:
translator_email = "[email protected]"
if len(translator.strip()) <2:
translator = "Kaniyam Foundation"
if len(ebook_maker_email.strip()) <2:
ebook_maker_email = "[email protected]"
if len(ebook_maker.strip()) <2:
ebook_maker = "Kaniyam Foundation"
if len(author_mail.strip()) < 2:
author_mail = "[email protected]"
text = "வணக்கம் " + author + ", \n" \
'உங்கள் மின்னூல் ' + book_name + ' வெளியிடப்பட்டது. \n' \
'இங்கே பார்க்கவும். ' + url +"\n\n" \
'உங்கள் தொடர்ந்த ஆதரவுக்கு மிக்க நன்றி! \n\n' \
'அன்புடன்,\n' \
'FreeTamilEbooks.com தன்னார்வலர்கள்'
data = {
'Messages': [
{
"From": {
"Email": "[email protected]",
"Name": "Publisher FreeTamilEbooks.com"
},
"To": [
{
"Email": author_mail,
"Name": author
}
],
"CC": [
{
"Email": "[email protected]",
"Name": "கணியம் அறக்கட்டளை"
},
{
"Email": artist_email,
"Name": artist
},
{
"Email": translator_email,
"Name": translator
},
{
"Email": ebook_maker_email,
"Name": ebook_maker
}
],
"Subject": 'உங்கள் மின்னூல் ' + book_name + ' வெளியிடப்பட்டது.',
"TextPart": text,
}
]
}
result = mailjet.send.create(data=data)
print(result.status_code)
print(result.json())
mastodon = Mastodon(
access_token = mastodon_access_token,
api_base_url = mastodon_url
)
toot = "மின்னூல்: " + book_name + "\n" \
" " + url + "\n" \
"உரிமை: கிரியேட்டிவ் காமன்சு.படிக்கலாம்,பகிரலாம். \n" \
" #Tamil #Ebooks #Kaniyam #தமிழ் #கணியம் #CreativeCommons"
mastodon.status_post(toot)
print("Done")
os.system("rm *.log")
print("Book URL is : " + url)
if github_issue_number:
g = Github(git_username, git_password)
repo = g.get_repo("KaniyamFoundation/Ebooks")
issue = repo.get_issue(number=github_issue_number)
body = "இங்கே வெளியிட்டுள்ளோம் - " + url
issue.create_comment(body)
issue.edit(state="closed")
issue.delete_labels()
print("Closed the issue https://github.com/KaniyamFoundation/Ebooks/issues/" + str(github_issue_number) )
r = requests.get(image_url) # create HTTP response object
with open("cover_image.jpg",'wb') as f:
f.write(r.content)
send_image_to_telegram("./cover_image.jpg")
telegram_content = url + "\n\n" + book_title + " - " + category + " - " + author + "\n\n" + "உரிமை – கிரியேட்டிவ் காமன்ஸ். எல்லாரும் படிக்கலாம், பகிரலாம்.\n\n"
send_text_to_telegram(telegram_content)
os.system("date")