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