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

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