Automatically encode/decode stock tickers with a dot so they can be stored in mongodb Remove print debug code
26 lines
632 B
Python
26 lines
632 B
Python
# Utility script to port from flatfile to database
|
|
|
|
import config as cfg
|
|
import flatfile as f
|
|
import mongo as m
|
|
import json
|
|
|
|
with open(cfg.database) as f:
|
|
data = json.loads(f.read())
|
|
|
|
for user in data.keys():
|
|
print("\n\nUser:", user)
|
|
print("Portfolio:")
|
|
|
|
for stock in data[user]["portfolio"].keys():
|
|
ticker = stock
|
|
amount = data[user]["portfolio"][stock]
|
|
m.add_stock(user, ticker, amount)
|
|
|
|
print("Watchlist:")
|
|
for stock in data[user]["watchlist"].keys():
|
|
ticker = stock
|
|
amount = data[user]["watchlist"][stock]
|
|
m.watch(user, ticker, amount)
|
|
|
|
print("[*] Done!")
|