Created
March 28, 2018 17:49
-
-
Save Safihre/0f0173f2ff7cced93c4b7e02671f743e to your computer and use it in GitHub Desktop.
Testing of Sanders files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import csv | |
import pprint | |
### | |
### BASIC IMPORTING | |
### | |
# Fields: | |
# 0: Server | |
# 1: IP | |
# 2: TLSv | |
# 3: Connection | |
# 4: Basic-SSL | |
# 5: Full-fail | |
fieldnames = ('server', 'ip_check', 'tlsv', 'connect', 'basic_ssl', 'full_ssl') | |
# All server-info | |
all_servers_full = {} | |
all_csvs = glob.glob('newsservers*.csv') | |
for fname in all_csvs: | |
# Extract the date | |
date = fname[-14:-4] | |
# Read and parse files | |
with open(fname, 'rb') as csvfile: | |
csvreader = csv.DictReader(csvfile, fieldnames=fieldnames) | |
for row in csvreader: | |
# Skip if we couldn't even connect via SSL | |
if row['connect'] != "OK": | |
continue | |
# New server? | |
if row['server'] not in all_servers_full: | |
all_servers_full[row['server']] = {} | |
# Add the result | |
all_servers_full[row['server']][date] = row['full_ssl'] | |
### | |
### FIND CONVERTERS | |
### | |
converters = 0 | |
converter_names = [] | |
converter_days = {} | |
for server in all_servers_full: | |
was_bad = False | |
# Need to sort on date to be sure (dict-keys are unsorted) | |
date_list = sorted(all_servers_full[server], key=lambda d: map(int, d.split('-'))) | |
# Check'em all | |
for index, date in enumerate(date_list): | |
# Skip if good from start | |
if index == 0 and all_servers_full[server][date] == "OK": | |
break | |
if all_servers_full[server][date] == "NOK": | |
# Bad now | |
was_bad = True | |
elif was_bad: | |
# It was bad before, now it's good! | |
converters += 1 | |
converter_names.append(server) | |
# And when did they convert? | |
# We only really care about the month | |
date_month = date[0:7] | |
if date_month not in converter_days: | |
converter_days[date_month] = 0 | |
converter_days[date_month] += 1 | |
break | |
### | |
### PRINT FINDINGS | |
### | |
print '\nConverted:', converters | |
print '-----------------------' | |
print '\n'.join(converter_names) | |
print '\nConverted in month:' | |
print '-----------------------' | |
for date_month in sorted(converter_days, key=lambda d: map(int, d.split('-'))): | |
print date_month, converter_days[date_month] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment