-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtui.py
More file actions
49 lines (41 loc) · 2.04 KB
/
tui.py
File metadata and controls
49 lines (41 loc) · 2.04 KB
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
import os.path
import colorama
import sys
import time
import logging
import scrapper
colorama.init()
logging.basicConfig(level=logging.CRITICAL)
print(colorama.Back.GREEN + colorama.Fore.GREEN + colorama.Style.BRIGHT + '### Israblog Blog Backup v{0} ###'.format(scrapper.__VERSION__) + colorama.Style.RESET_ALL)
print(colorama.Back.YELLOW + colorama.Fore.YELLOW + colorama.Style.BRIGHT + 'Written by Itay Brandes\r\n' + colorama.Style.RESET_ALL)
if len(sys.argv) >= 2:
print("Requested to backup blog {}.".format(sys.argv[1]))
blogid = sys.argv[1]
if not blogid.isdigit() or not 1 <= int(blogid) <= 900000:
print(colorama.Fore.RED + colorama.Style.BRIGHT + "Input invalid." + colorama.Style.RESET_ALL)
sys.exit(1)
if not scrapper.is_blog_exists(blogid):
print(colorama.Fore.RED + colorama.Style.BRIGHT + "Blog does not exist, or it's private." + colorama.Style.RESET_ALL + " If it's private, please set it to public beforehand.")
sys.exit(1)
if len(sys.argv) >= 3:
print("Setting Israblog Hostname to {}".format(sys.argv[2]))
scrapper.ISRABLOG_HOSTNAME = sys.argv[2]
else:
ans = input("Please enter Israblog current URL, or leave empty for default: [{}] ".format(scrapper.ISRABLOG_HOSTNAME))
if ans:
scrapper.ISRABLOG_HOSTNAME = ans
while True:
blogid = input("Please enter the blog ID you want to backup: ")
while not blogid or not blogid.isdigit() or not 1 <= int(blogid) <= 900000:
print(colorama.Fore.RED + colorama.Style.BRIGHT + "Input invalid." + colorama.Style.RESET_ALL + " Please enter the blog ID you want to backup: ", end="")
blogid = input()
if not scrapper.is_blog_exists(blogid):
print(colorama.Fore.RED + colorama.Style.BRIGHT + "Blog does not exist, or it's private." + colorama.Style.RESET_ALL + " If it's private, please set it to public beforehand.")
else:
break
start = time.time()
dl_path = os.path.join(scrapper.BACKUP_FOLDER, "blog{0}".format(blogid))
scrapper.main(blog_id=blogid, dl_path=dl_path)
end = time.time()
print("Took {:.2f} seconds.".format(end - start))
os.startfile(os.path.join(dl_path, 'landing.htm'))