-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmain_parser.py
More file actions
86 lines (75 loc) · 3.42 KB
/
main_parser.py
File metadata and controls
86 lines (75 loc) · 3.42 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
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
import os
from Parser import Parser
import asyncio
from assist_func import add_to_existing_file, convert_to_csv
from account_manager import auth_for_parsing
def what_to_do():
parser_menu = input ('Choose how to scrape users:\n1. Scrape users only with status Last seen Recently\n2. Parse without any filter'
'\n3. Scrape users from comments in the channel\n4. Scrape users, who were online later than '
'a certain date\n5. Scrape users, who reacted in the group (by specific emoji or with any '
'emoji)\n6. Scrape users, who were online later than a certain date n time\n7. Quit\n - ')
while parser_menu not in '1234567':
parser_menu = input (
'Choose how to scrape users:\n1. Scrape users only with status Last seen Recently\n2. Parse without any filter'
'\n3. Scrape users from comments in the channel\n4. Scrape users, who were online later than '
'a certain date\n5. Scrape users, who reacted in the group (by specific emoji or with any '
'emoji)\n6. Scrape users, who were online later than a certain date n time\n7. Quit\n - ')
return int(parser_menu)
async def extended_parser():
client = await auth_for_parsing ()
if client is None:
return
if not os.path.exists ('users.csv'):
open ('users.csv', 'w')
option = what_to_do()
if option == 1:
await parser(client)
elif option == 2:
await parser(client, without_filter=True)
elif option == 3:
# parse from channel worked
users = await Parser(client).get_from_comments()
if users:
add_to_existing_file (users)
print ('successfully parsed')
elif option == 4:
# parse by specific date
limit = input ('How many users do u want to parse? Press enter if all (tg limit is 10000 from one group): ')
if limit.isdigit ():
limit = int (limit)
users = await Parser (client).users_by_day_filter (limit=limit)
else:
users = await Parser (client).users_by_day_filter ()
if users:
add_to_existing_file (users)
print ('successfully parsed')
elif option == 5:
# get users that reacted in chat
users = await Parser(client).get_user_that_reacted_in_chat()
if users:
add_to_existing_file (users)
print ('successfully parsed')
elif option == 6:
users = await Parser (client).users_by_time_filter ()
if users:
add_to_existing_file (users)
print ('successfully parsed')
elif option == 7:
return
# fully functional old parser
async def parser(client, without_filter=None):
limit = input('How many users do u want to parse? Press enter if all (tg limit is 10000 from one group): ')
if limit.isdigit():
limit = int(limit)
if without_filter:
users = await Parser (client).parse_members (limit=limit, status_filter=None)
else:
users = await Parser (client).parse_members (limit=limit)
else:
if without_filter:
users = await Parser(client).parse_members(status_filter=None)
else:
users = await Parser(client).parse_members()
add_to_existing_file(users)
print('successfully parsed')
asyncio.run(extended_parser())