-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteract.py
94 lines (77 loc) · 3.34 KB
/
interact.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
import requests
from rich import console
from rich.console import Console
from requests import get
console = Console(style='cyan')
def sayHi():
console.print(
'''
Hey! Welcome to [white]Scorp[/white] - a tool for scrappig news pages,
profiles or any pages containing links.
If you want to search for some word(s), firstly
you'll have to create a [white]search unit[/white]. It's so
simple: just print [white]add[/white] and follow instructions.
For example:
add
Enter link: https://www.nytimes.com/
Enter word(s): coronavirus, data leak
Done! This will create a search unit with
'coronavirus' and 'data leak' keywords.
To run scan print [white]scan[/white]
Print [white]delete[/white] to remove word(s) from a search unit.
[white]Warning![/white] The program remembers all your search units
and already found words, so there's no need to
create search units everytime you run it. It won't
show you a word if it was already found.
To clear found links list print [white]clear found links[/white].
To delete all search units(scraps) print [white]clear scraps[/white].
If you want to see current scraps, print [white]show scraps[/white].
If you want to see list of found links, print [white]show found links[/white].
Having changed your mind, you can undo not finished action by pressing [white]Enter[/white].
Print [white]esc[/white], [white]exit[/white] or [white]escape[/white] to exit.
''',
highlight=False
)
def anlz(scrapObject, inp: str):
inp = str(inp).strip().lower()
if '-h' in inp or 'help' in inp:
sayHi()
elif inp == 'add':
console.print('Enter link: ', end='')
link = str(console.input('>>> ')).strip()
if link:
try:
response = get(link)
if response.status_code == 200:
console.print('Enter word(s) divided by \', \': ', highlight=False)
words = str(console.input('>>> ')).split(', ')
scrapObject.addScrap(*words, url=link)
else:
console.print('[red]There\'s a problem with this page. Try another one[/red]')
except:
console.print('[red]There\'s a problem with this page. Try another one[/red]')
else:
console.print('Cancelled')
elif inp == 'delete':
console.print('Enter link: ', end='')
link = str(console.input('>>> '))
if link:
console.print('Enter word(s) divided to be deleted by \', \': ', highlight=False)
words = str(console.input('>>> ')).split(', ')
scrapObject.delScrap(*words, url=link)
else:
console.print('Cancelled')
elif inp == 'clear found links':
scrapObject.clrFoundUrls()
console.print('Found links list cleared')
elif inp == 'clear scraps':
scrapObject.clrScraps()
console.print('Scraps list cleared')
elif inp == 'scan':
scrapObject.runScan()
elif inp == 'show scraps':
scrapObject.showScraps()
elif inp == 'show found links':
scrapObject.showFoundUrls()
elif inp == 'esc' or inp == 'escape' or inp == 'exit':
quit()