-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
97 lines (67 loc) · 2.46 KB
/
main.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
import TorFirefox
import PdfCompressor
import os
def main ():
browser = TorFirefox.getFirefoxBrowser()
url = 'http://pdfcompressor.com/'
browser.get(url)
# dir_path = os.path.dirname(os.path.realpath(__file__))
##################################
# replace 2.pdf with the fileame #
##################################
file_path = os.getcwd() + "/2.pdf"
print file_path
PdfCompressor.compressPDF(browser, file_path)
flag1 = PdfCompressor.downloadCompPDF(browser)
if(flag1): #flag1 =0 when there is no fle to be downloaded
TorFirefox.unzipFile(os.getcwd()+"/pdfcompressor.zip",os.getcwd())
os.remove(os.getcwd()+"/pdfcompressor.zip")
browser.close()
if __name__ == "__main__":
main()
'''
def main():
startWatchdog()
##############################################################
# update the file_path with the pdf path to be compressed. #
# Include the multiprocessing part when importing this file#
# in your code #
##############################################################
dir_path = os.path.dirname(os.path.realpath(__file__))
file_path = dir_path + "/" + "h2.pdf"
if os.path.isfile(file_path):
Compress(file_path)
else:
print file_path,"file dont exists"
def Compress(file_path):
browser = TorFirefox.getFirefoxBrowser()
url = 'http://pdfcompressor.com/'
browser.get(url)
PdfCompressor.compressPDF(browser, file_path)
print " ||||||| pdf = ", file_path, "uploaded ||||||||||"
flag = PdfCompressor.downloadCompPDF(browser)
## and unzipping it in the current folder
# print os.getcwd()
if(flag): #flag1 =0 when there is no fle to be downloaded
print os.getcwd()
TorFirefox.unzipFile(os.getcwd()+"/pdfcompressor.zip",os.getcwd())
os.remove(os.getcwd()+"/pdfcompressor.zip")
print "file compressed ! "
#close the browser after doint all the shit
TorFirefox.closeBrowser(browser)
def watchdog():
### running daemon that checks if the file is downoaded completely or not
w = watchdogg.Watcher()
w.run()
def startWatchdog():
### below updation is necessary in order to open watchdog
# coz after the last step is done (prev run) the file is updated to "DONE"
# and this same string is also required to close watchdog after all unzipping is done
#
with open('/home/gugli/Documents/script_py/PdfCompressor/checkDownStatus.txt','w') as outFile:
outFile.write("blah")
p1 = multiprocessing.Process(name='p1', target=watchdog)
p1.start()
# p2 = multiprocessing.Process(name='p', target=sud)
# p2.start()
'''