Last active
December 3, 2021 05:41
-
-
Save cmpute/b6b2c01be32e6a1484c9974cb19b5d8d to your computer and use it in GitHub Desktop.
Fetch GIMPS result into database
This file contains hidden or 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
# requirements: pandas, lxml | |
import pandas as pd | |
import sqlite3, time | |
from datetime import datetime | |
def fetch(): | |
df = pd.read_html('https://www.mersenne.org/report_recent_results/')[1] # first table is the login form | |
print(datetime.now().strftime('%c'), ">> Table fetched, data summary:") | |
print(df) | |
df.rename(columns = { | |
'Member Name': 'user', | |
'Computer Name':'computer', | |
'MN': 'exponent', | |
'Type': 'task', | |
'UTC Time Received': 'time', | |
'Days': 'age', | |
'GHz-days': 'credit', | |
'Result': 'comment' | |
}, inplace = True) | |
df['time'] = pd.to_datetime(df['time']) | |
df['hash'] = df.apply(lambda r: hash(tuple(r)), axis=1) | |
df.set_index('hash', inplace=True) | |
conn = sqlite3.connect('gimps.db3') | |
df.to_sql('results', conn, if_exists='append') | |
conn.close() | |
while True: | |
fetch() | |
print(datetime.now().strftime('%c'), '>> Successfully updated the database. Wait for an hour...') | |
time.sleep(3600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment