Skip to content

Instantly share code, notes, and snippets.

@anarcie
Created June 16, 2017 16:30
Show Gist options
  • Save anarcie/e36b8ccbf72bfbf1b7edeeed9728c1af to your computer and use it in GitHub Desktop.
Save anarcie/e36b8ccbf72bfbf1b7edeeed9728c1af to your computer and use it in GitHub Desktop.
import requests, json, os, sqlite3
sub_url = 'https://www.iceposeidon.com/api/v1/subscriptions'
subs_count = 0;
subs_tier_1 = 0;
subs_tier_2 = 0;
subs_tier_3 = 0;
sub_tier_1_cost = 4.99
sub_tier_2_cost = 9.99
sub_tier_3_cost = 19.99
#used for storing users
storeData = True
dbConn = False
def getSubs():
r = requests.get(sub_url)
subs = r.json()
return subs['subscriptions']
#Create the DB and make sure we have a table to write to.
def connectDatabase():
dbConn = sqlite3.connect('CxDB.db')
res = dbConn.execute("create table if not exists Subs (username TEXT, subtier INTEGER, DATE NUMERIC)")
dbConn.commit()
return dbConn
#Insert a sub into the sqlite db for sub trending/analysis
def insertSub(conn, usr,tier):
sql = "INSERT INTO Subs (username, subtier, DATE) VALUES ('%s', %i, CURRENT_TIMESTAMP)" % (usr, int(tier))
conn.execute(sql)
conn.commit()
#Get our subs and get a DB Connection to store them
subs = getSubs()
if(storeData): dbConn = connectDatabase()
#Loop over out subs, add them to the db and inc data
for sub in subs:
subs_count += 1
username = subs[sub]["userName"]
subtier = subs[sub]["subtier"]
if (storeData): insertSub(dbConn, username , subtier)
if (subtier == "1"): subs_tier_1 += 1
if (subtier == "2"): subs_tier_2 += 1
if (subtier == "3"): subs_tier_3 += 1
print str(username) + " is Tier " + str(subtier)
#Print out our data
print "Total Subs: " + str(subs_count)
print "Tier 1 Subs: " + str(subs_tier_1) + " | Euros: " + str(subs_tier_1 * sub_tier_1_cost)
print "Tier 2 Subs: " + str(subs_tier_2) + " | Euros: " + str(subs_tier_2 * sub_tier_2_cost)
print "Tier 3 Subs: " + str(subs_tier_3) + " | Euros: " + str(subs_tier_3 * sub_tier_3_cost)
sub_total_income = (subs_tier_1 * sub_tier_1_cost) + (subs_tier_2 * sub_tier_2_cost) + (subs_tier_3 * sub_tier_3_cost)
sub_total_income_us = sub_total_income * 1.12
print "Totals from new Sub Model Euros:" + str(sub_total_income)
print "Totals from new Sub Model $" + str(sub_total_income_us)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment