Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python3
#
# The_Gutenberg_Internet_analogy.py
#
# author : Sreejith S
# email : echo $(base64 -d <<< NDQ0bGhjCg==)@gmail.com
# date : Sun 28 Apr 2019 19:57:28 IST
# ver :
'''
Dependency Install:
$ pip3 install wikipedia
Run:
$ python3 The_Gutenberg_Internet_analogy.py
Untested code
Inspired by: https://mbuliga.github.io/gutenberg-net.html
'''
import wikipedia
import math
from datetime import date
from random import choice
year = input("Input a year : ")
#validate input
if not year.isdigit():
raise ValueError("Invalid input - enter a year.")
input_year = int(year)
curr_year = date.today().year
gutenberg_year = 1436
arpanet_year = 1969
exp = math.log(5)/math.log(2) #ln
if input_year > curr_year or input_year < gutenberg_year:
raise ValueError("Enter a year after {} and before {}".format(gutenberg_year, curr_year+1))
if input_year < arpanet_year:
dt_historic = (input_year - gutenberg_year)/10
dt_today = math.pow(dt_historic, 1/exp)
output_year = round(dt_today*10 + arpanet_year)
if input_year >= arpanet_year:
dt_today = (input_year - arpanet_year)/10
dt_historic = math.pow(dt_today, exp)
output_year = round(dt_historic*10 + gutenberg_year)
print(output_year)
input_events = wikipedia.page(str(input_year)).content.split('\n')
#remove summary
events_header = '== Events =='
input_events = input_events[input_events.index(events_header):]
try:
output_events = wikipedia.page(str(output_year)).content.split('\n')
output_events = output_events[output_events.index(events_header):] #remove summary
except ValueError:
if output_year < 2100:
output_events = ['https://www.futuretimeline.net/21stcentury/21stcentury.htm']
else:
output_events = ['https://www.futuretimeline.net/22ndcentury/22ndcentury.htm']
# remove headers, empty elements, and elements shorter than 42
input_events = [i for i in input_events if '==' not in i and i and len(i) > 42]
output_events = [i for i in output_events if '==' not in i and i and len(i) > 42]
#choose random event
event1 = choice(input_events)
event2 = choice(output_events)
output = "{} ({}) --- {} ({})".format(event1, input_year, event2, output_year)
print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.