-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_my_issue.py
90 lines (71 loc) · 2.58 KB
/
get_my_issue.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
#!/usr/bin/env python3
import time
import configparser
import os
import methods
def main():
#today = time.asctime(time.localtime(time.time()))
local_time = time.localtime()
today = time.strftime("%a, %d %b %Y", local_time)
print('\nHi! today is {} '.format(today))
print('[*]Going to download today\'s issue...')
print('[>]In case connection error occurs try after sometime. Even then if problem persists, Github!!')
print('[*]Reading the config file config.ini ...')
ini = configparser.ConfigParser()
try:
ini.read('config.ini')
except:
print('No config file found. Creating one...') #create the ini file
ini['DEFAULT']['auto_pilot'] = input('\nauto mode(0/1): ')
ini['1']['url'] = input('\nurl :')
ini['1']['method_name'] = input('\nmethod_name: ')
#print(ini,'###########')
mode = ini['DEFAULT']['auto_pilot'] # 1 for auto; no user interaction
if(mode == '1'):
stat = auto_pilot(today,ini,local_time)
else:
pass#stat = manual.main(today,ini)
if stat:
print('\n[*]Hope you have the file...Bye!!')
else:
print('\n[*]Din\'t work! Trace and pull or create an issue...you know :)')
def auto_pilot(today,ini,local_time):
print('[*]Auto-mode...\n')
file_name = '_the_Hindu__' + today + '.pdf'
if os.path.exists(file_name):
if ini['DEFAULT']['repeated_download'] == 0:
print('[*]File already exists!Need not download. \n')
return True
else:
try:
os.rename(file_name,'old_'+file_name) # to rename existin in format z_old.bah.pdf
except:
pass
#method params
section_no = ini['DEFAULT']['use_section']
url = ini[section_no]['url']
method_name = ini[section_no]['method_name']
date_x = int(ini[section_no]['date_x'])
date_y = int(ini[section_no]['date_y'])
url_x = int(ini[section_no]['url_x'])
url_y = int(ini[section_no]['url_y'])
method_dict = {'name':method_name, 'url':url, 'date_x':date_x, 'date_y':date_y, 'url_x':url_x, 'url_y':url_y}
stat = methods.use_method(method_dict,file_name,match_time=local_time)
if stat:
if ini['DEFAULT']['move_old'] == '1':
for l in os.listdir(os.curdir): #to move older issues to old_issuse dir
#print(l)
if l.endswith('.pdf') and not (l == file_name) and ('_the_Hindu__' in l): #to avoid today's file to be copied to old dir
try:
old_issue_dir = ini['DEFAULT']['old_issue_dir']
os.rename(l,'{}/{}'.format(old_issue_dir,l))
print('{} moved to {}.'.format(l,old_issue_dir))
except:
print('\n[*]Failed to move the older issues. Do it manualy. :(')
else:
pass #don't move the files to old_issues dir
return True
else:
return False
if __name__ == '__main__':
main()