Last active
November 26, 2017 08:39
-
-
Save greenywd/3787b321b028f2142acb8cbbc190779b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
from __future__ import division | |
import os | |
import sys | |
import datetime | |
import pygsheets | |
import whatapi | |
# Set constants | |
DATE = datetime.datetime.now().strftime("%d-%m-%y %H:%M:%S") | |
uploaded = float(0.00) | |
downloaded = float(0.00) | |
ratio = None | |
torrentsUploaded = int(0) | |
torrentsSeeding = int(0) | |
torrentsSnatched = int(0) | |
seedingSize = float(0.00) | |
USER_ID = 25474 | |
def get_credentials(): | |
"""Function to check for valid OAuth access tokens.""" | |
gc = pygsheets.authorize(outh_file="creds.json") | |
return gc | |
def submit_into_spreadsheet(up, down, rat,tUp, tSeed, tSnatch): | |
"""Function to submit speedtest result.""" | |
gc = get_credentials() | |
speedtest = gc.open(os.getenv('SPREADSHEET', 'APL Stats')) | |
sheet = speedtest.sheet1 | |
data = [DATE, up, down, rat, tUp, tSeed, tSnatch] | |
sheet.append_table(values=data) | |
def getTrackerData(): | |
print("\t Logging in....") | |
api = whatapi.WhatAPI(username='no', password='hell naw', server='https://apollo.rip/') | |
print("\t Getting upload...") | |
global uploaded | |
uploaded = str(round((((api.request("user", id=USER_ID)['response']['stats']['uploaded'])/1024)/1024)/1024, 2)) | |
print("\t Getting download...") | |
global downloaded | |
downloaded = str(round((((api.request("user", id=USER_ID)['response']['stats']['downloaded'])/1024)/1024)/1024, 2)) | |
print("\t Getting ratio...") | |
global ratio | |
# ratio from APL is returned as a string with a comma for some reason (i.e '1,234.5678') so we need to remove the comma | |
before = api.request("user", id=USER_ID)['response']['stats']['ratio'] | |
after = before.replace(",","") | |
ratio = round(float(after),2) | |
print("\t Getting torrents uploaded...") | |
global torrentsUploaded | |
torrentsUploaded = api.request("user", id=USER_ID)['response']['community']['uploaded'] | |
print("\t Getting torrents snatched...") | |
global torrentsSnatched | |
torrentsSnatched = api.request("user", id=USER_ID)['response']['community']['snatched'] | |
print("\t Getting torrents seeding...") | |
global torrentsSeeding | |
torrentsSeeding = api.request("user", id=USER_ID)['response']['community']['seeding'] | |
def main(): | |
# Check for proper credentials | |
print("Checking OAuth validity...") | |
credentials = get_credentials() | |
# Run speedtest and store output | |
print("Getting tracker data...") | |
getTrackerData() | |
print("Got tracker data!") | |
# Write to spreadsheet | |
print("Writing to spreadsheet...") | |
submit_into_spreadsheet(uploaded, downloaded, ratio, torrentsUploaded, torrentsSeeding, torrentsSnatched) | |
print("Successfuly written to spreadsheet!") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment