@@ -15,6 +15,44 @@ def parse_types(args):
1515else :
1616return args .types
1717
18+ def run (packpub ,args ,config ):
19+ packpub .run ()
20+
21+ if args .dev :
22+ log_json (packpub .info )
23+
24+ log_success ('[+] book successfully claimed' )
25+
26+ upload = None
27+ upload_info = None
28+ packpub_info = None
29+
30+ if not args .claimOnly :
31+ types = parse_types (args )
32+
33+ packpub .download_ebooks (types )
34+
35+ if args .extras :
36+ packpub .download_extras ()
37+
38+ if args .archive :
39+ raise NotImplementedError ('not implemented yet!' )
40+
41+ if args .upload is not None :
42+ upload = Upload (config ,args .upload )
43+ upload .run (packpub .info ['paths' ])
44+
45+ if upload is not None and upload is not SERVICE_DRIVE :
46+ log_warn ('[-] skip store info: missing upload info' )
47+ elif args .store is not None :
48+ Database (config ,args .store ,packpub .info ,upload .info ).store ()
49+
50+ if args .notify :
51+ if upload is not None :
52+ upload_info = upload .info
53+
54+ Notify (config ,packpub .info ,upload_info ,args .notify ).run ()
55+
1856def main ():
1957parser = argparse .ArgumentParser (
2058description = 'Download FREE eBook every day from www.packtpub.com' ,
@@ -41,52 +79,25 @@ def main():
4179now = datetime .datetime .now ()
4280log_info ('[*] {date} - Fetching today\' s books' .format (date = now .strftime ("%Y-%m-%d %H:%M" )))
4381
82+ packtpub = None
83+
4484try :
45- #ip_address()
4685config = config_file (args .config )
47- types = parse_types (args )
4886
87+ #ip_address()
88+ log_info ('[*] getting daily free ebook' )
4989packpub = Packpub (config ,args .dev )
50- packpub .run ()
51-
52- if args .dev :
53- log_json (packpub .info )
54-
55- log_success ('[+] book successfully claimed' )
56-
57- upload = None
58-
59- if not args .claimOnly :
60- packpub .download_ebooks (types )
61-
62- if args .extras :
63- packpub .download_extras ()
64-
65- if args .archive :
66- raise NotImplementedError ('not implemented yet!' )
67-
68- if args .upload is not None :
69- upload = Upload (config ,args .upload )
70- upload .run (packpub .info ['paths' ])
71-
72- if upload is not None and upload is not SERVICE_DRIVE :
73- log_warn ('[-] skip store info: missing upload info' )
74- elif args .store is not None :
75- Database (config ,args .store ,packpub .info ,upload .info ).store ()
76-
77- if args .notify :
78- upload_info = None
79-
80- if upload is not None :
81- upload_info = upload .info
82-
83- Notify (config ,packpub .info ,upload_info ,args .notify ).run ()
90+ run (packpub ,args ,config )
8491
8592except KeyboardInterrupt :
8693log_error ('[-] interrupted manually' )
94+
8795except Exception as e :
8896log_debug (e )
89- log_error ('[-] something weird occurred, exiting...' )
97+ if args .notify :
98+ Notify (config ,None ,None ,args .notify ).sendError (e ,'global' )
99+
100+ log_info ('[*] done' )
90101
91102if __name__ == '__main__' :
92103print ("""