-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
146 lines (140 loc) · 4.91 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import json
from typing import ItemsView
import yfn
import os
from os.path import exists
from datetime import date
import time
import click
import requests
version = "ghb0.0.00"
updateurl = "https://raw.githubusercontent.com/ririinsta/stock-sim/main/info%20for%20program/ver"
class Main():
def firstRun():
f = open('conf.cfg', 'a')
f.write('{"firstRunDate": "' + str(date.today()) + '", "mainProfile": "main.prf"}')
f.close()
def startUp():
if exists('./conf.cfg'):
config = json.loads(open("conf.cfg", "r").readline())
test = open(config['mainProfile']).readline()
profile = json.loads(test)
balance = profile['bal']
portfolio = profile['port']
return [balance, portfolio]
else:
Main.firstRun()
return False
def onClose(bal, port):
if exists('./main.prf'):
click.clear()
os.remove('main.prf')
f = open("main.prf", "a")
x = {
"profilename": "main",
"bal": bal,
"port": port
}
f.write(json.dumps(x))
f.close()
else:
f = open("main.prf", "a")
x = {
"profilename": "main",
"bal": bal,
"port": port
}
f.write(json.dumps(x))
f.close()
def mainMenu(bal, port):
click.clear()
print("1. Check Balance")
print("2. Check Portfolio")
print("3. Buy Stock")
print("4. Sell Stock")
print("5. Advance Day")
print("6. test")
print("i. Info")
print("7. Close")
awn = input("> ")
Main.checkOption(awn, bal, port)
def checkOption(awn, balance, portfolio):
click.clear()
if awn == "1":
print("Balance: " + str(balance))
input("Press any key to continue")
if awn == "2":
index = 0
for item in portfolio:
index = index + 1
itemarray = item.split(",")
print(str(index) + ". " + itemarray[2] + " " + itemarray[0] + " bought at " + itemarray[1] + " a piece")
input()
if awn == "3":
print("What stock?")
stock = input("> ")
returned = Main.purchaseStock(stock, balance, portfolio)
balance = returned[0]
portfolio = returned[1]
if awn == "4":
among = input()
for item in portfolio:
if item.split()[0] == among:
print(item)
print("")
input("Press any key to continue")
if awn == "5":
input()
if awn == "6":
print(os.getpid())
input()
if awn == "i":
print("Made by Riri")
print("Version: " + version)
print("Press U to check for updates")
inp = input("Waiting for user input > ")
if inp == "U":
updatefile = requests.get(updateurl)
open('tempupdfile.temp', 'wb').write(updatefile.content)
ver = open('tempupdfile.temp', "r").readline()
if ver == version:
print("Up to date!")
input("Press any key to continue")
else:
print("Current Version: " + version)
print("New Version: " + ver)
input("Press any key to update.")
update = requests.get("https://raw.githubusercontent.com/ririinsta/stock-sim/main/info%20for%20program/update.py")
open('update.py', 'wb').write(update.content)
#os.system("python3.9 update.py " + str(os.getpid()) + "'")
os.system("taskkill /f /pid " + str(os.getpid()))
os.remove("tempupdfile.temp")
if inp == "CSTM-PKG":
ver = open('tempupdfile.temp', "r").readline()
if ver == version:
print("Up to date!")
input("Press any key to continue")
else:
print("Current Version: " + version)
print("New Version: " + ver)
input("Press any key to update.")
if awn == "7":
Main.onClose(balance, portfolio)
exit()
Main.mainMenu(balance, portfolio)
def purchaseStock(stock, balance, portfolio):
stonk = yfn.download(stock, period="1d")
jsontest = r"" + stock + r"," +str(round(stonk['High'][str(date.today())], 2)) + r"," + r"1" + r""
portfolio.append(jsontest)
print(portfolio)
input()
return [balance, portfolio]
onrun = Main.startUp()
balance = 200
portfolio = []
if onrun == False:
time.sleep(0)
else:
balance = onrun[0]
portfolio = onrun[1]
awn = Main.mainMenu(balance, portfolio)