Skip to content

Instantly share code, notes, and snippets.

@tinybike
Last active September 2, 2015 21:25
Show Gist options
  • Select an option

  • Save tinybike/7858f2c854c0a036ef12 to your computer and use it in GitHub Desktop.

Select an option

Save tinybike/7858f2c854c0a036ef12 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import division
import os
import json
import csv
import datetime as dt
BTC_PRICE = 229.27
DATA_DIR = "data"
COINS = 100000000
def write_to_csv(group, outpath):
with open(outpath, "w+") as outfile:
writer = csv.writer(outfile, delimiter=',')
writer.writerow([
"email",
"full name",
"balance",
"last buy-in time",
"account url",
])
for account in group:
if "balance" in account["customData"]:
balance = account["customData"]["balance"]
else:
balance = 0
if "time" in account["customData"]:
when = dt.datetime.utcfromtimestamp(
account["customData"]["time"]
).isoformat()
else:
when = 0
writer.writerow([
unicode(account["email"]).encode("utf-8"),
unicode(account["fullName"]).encode("utf-8"),
balance,
when,
unicode(account["href"]).encode("utf-8"),
])
def main():
accounts, buyers, whales, superwhales = [], [], [], []
for filename in os.listdir(DATA_DIR):
datapath = os.path.join(DATA_DIR, filename)
if os.path.isfile(datapath):
with open(datapath) as f:
info = json.load(f)
accounts.append(info)
if "balance" in info["customData"]:
if info["customData"]["balance"] > 0:
buyers.append(info)
if info["customData"]["balance"] > 10000 * COINS / BTC_PRICE:
whales.append(info)
if info["customData"]["balance"] > 50000 * COINS / BTC_PRICE:
superwhales.append(info)
# print summary
print "Number of accounts:", len(accounts)
print "Number of buyers:", len(buyers)
print "Number of whales (> $10k):", len(whales)
print "Number of superwhales (> $50k):", len(superwhales)
# write info to csv files
write_to_csv(accounts, "accounts.csv")
write_to_csv(buyers, "buyers.csv")
write_to_csv(whales, "whales.csv")
write_to_csv(superwhales, "superwhales.csv")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment