-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (42 loc) · 1.77 KB
/
main.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
import conf
from lib import query_yes_no, discrepancy, export_csv, parse_niches, export_html, export_pdf, get_title_suggestions, \
search_videos, manual_check
from datetime import datetime, timedelta
from pytz import UTC
# parse and check niches
niches = parse_niches(conf.QUERIES_FILE)
if not query_yes_no(f'{niches}\n\nDoes this look correct? [Y/n]:', default='yes'):
print(f'This is the value of conf.QUERIES_FILE: {conf.QUERIES_FILE}.\nCheck that the file name is correct and '
'the contents of the file.')
exit(0)
now = datetime.now(UTC)
date_str = now.strftime('%d-%m-%y')
# cap number of videos to be fetched to avoid exceeding YT API quota
max_pages_per_niche = int(conf.YT_DAILY_TOKENS / (len(niches) * 102))
for niche in niches:
date_cutoff = datetime.isoformat(now - timedelta(days=niche['days']))
q = niche['q']
print(f'Searching \"{q}\" starting at {date_cutoff}...')
niche['videos'] = search_videos(
q=q,
date_cutoff=date_cutoff,
max_pages=max_pages_per_niche,
max_videos=20,
max_subscribers=niche['max_subscribers']
)
niche['total_views_count'] = 0
for video in niche['videos']:
niche['total_views_count'] += int(video['views'])
print(f'Done.\n\n')
if query_yes_no('Do you want to check each video? [Y/n]:', default='yes'):
manual_check(niche['videos'])
print(f'Done. Detecting discrepancies...')
# tag discrepancy factor
discrepancy(niche['videos'])
print(f'Done. Requesting title suggestions...')
niche['titles'] = get_title_suggestions(q)
# Generate reports
result_filename = 'collection_result_' + date_str
export_csv(result_filename, niches, date_str)
export_html(result_filename, niches, date_str)
export_pdf(result_filename, niches, date_str)