chg: Make the stats tool more generic

pull/128/head
Raphaël Vinot 2020-11-20 12:17:54 +01:00
parent c17b0fc6d3
commit 254211e895
1 changed files with 31 additions and 32 deletions

View File

@ -3,34 +3,33 @@ import calendar
import datetime import datetime
lookyloo = Lookyloo() lookyloo = Lookyloo()
scraped = lookyloo.capture_uuids
date = datetime.datetime.now() stats = {}
year = date.year
for i in range(2020,year+1): for uuid in lookyloo.capture_uuids:
count_year=0 cache = lookyloo.capture_cache(uuid)
redirects_year=0 if 'timestamp' not in cache:
print (i) continue
for j in range(1,12): date = datetime.datetime.fromisoformat(cache['timestamp'].rstrip('Z'))
count=0 if date.year not in stats:
redirects=0 stats[date.year] = {}
redir=0 if date.month not in stats[date.year]:
for k in scraped: stats[date.year][date.month] = {'analysis': 0, 'redirects': 0}
cached = lookyloo.capture_cache(k) stats[date.year][date.month]['analysis'] += 1
try: stats[date.year][date.month]['redirects'] += len(cache['redirects'])
if cached['timestamp'].startswith(str(i)+"-"+str('{:02d}'.format(j))):
count+=1
try : for year, data in stats.items():
redir+=len(cached['redirects']) print('Year:', year)
except: yearly_analysis = 0
print('oup') yearly_redirects = 0
except: for month in sorted(data.keys()):
pass stats = data[month]
print(calendar.month_name[j]) print(' ', calendar.month_name[month])
print("Number of analysis : "+str(count)) print("\tNumber of analysis :", stats['analysis'])
print("Number of redirects : "+str(redir)) print("\tNumber of redirects :", stats['redirects'])
redirects_year+=redir yearly_analysis += stats['analysis']
count_year+=count yearly_redirects += stats['redirects']
print("Total of analysis for year "+str(i)+" : "+str(count_year))
print("Total of redirects for year "+str(i)+" : "+str(redirects_year)) print(" Sum analysis:", yearly_analysis)
print(" Sum redirects:", yearly_redirects)