-
Notifications
You must be signed in to change notification settings - Fork 0
/
Convertor.py
155 lines (126 loc) · 4.53 KB
/
Convertor.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
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python3
#######################################################
# Duino-Coin Convertor #
# https://github.com/swanserquack/duinocoin-convertor #
# No copyright #
#######################################################
import requests
import colorama
import ujson
import filecmp
import os
import shutil
from os import path, mkdir
from pathlib import Path
from colorama import init
from colorama import Fore, Back, Style
init()
Folder = "Resources"
Updater = "Update Resources"
Updater1 = "Update Resources/Updater.py"
Updater2 = "Updater.py"
values = "/values.json"
if not path.exists(Updater):
mkdir(Updater)
if not Path(Updater + "/Updater.py").is_file(): # Same here as above
tempd = requests.get(
"https://raw.githubusercontent.com/swanserquack/duinocoin-convertor/main/Updater.py"
)
with open(Updater + "/Updater.py", "wb") as f:
f.write(tempd.content)
updateresult = filecmp.cmp(Updater1, Updater2, shallow=False)
if updateresult == False:
sf = open(Updater1, "rb")
tf = open(Updater2, "wb")
tf.write(sf.read())
sf.close()
tf.close()
shutil.rmtree(Updater)
if updateresult == True:
shutil.rmtree(Updater)
if not path.exists(Folder):
mkdir(Folder) # If the Resource folder does not exist then it creates it
if not Path(
Folder + values
).is_file(): # If the values.json file does not exist then it creates it
tempd = requests.get(
"https://raw.githubusercontent.com/swanserquack/duinocoin-convertor/main/Resources/values.json"
)
with open(Folder + values, "wb") as f:
f.write(tempd.content) # Writes the values.json file
with open(Folder + values, "r", encoding="utf-8") as values:
values = ujson.load(values) # Loads it
response_Duino = requests.get("https://server.duinocoin.com/statistics") # Grabs Data
Duino_Output = response_Duino.text
parse_json = ujson.loads(
Duino_Output
) # Turns the API output into a python dictionary and then sets it as the variable parse_json
DuinoPrice = parse_json[
"Duco price"
] # Searches the dictionary for Duco price and sets DuinoPrice to the value
def convert(ID):
output = response.text
parse_json = ujson.loads(
output
) # Turns the API output into a python dictionary and then sets it as the variable parse_json
convert.Price = parse_json[ID][
"usd"
] # Goes through the ID variable then the usd to get the price
return convert.Price
def calculationto(ID):
duinoamount = float(input("How many Duino-Coins do you have?"))
duinototal = DuinoPrice * duinoamount
finaloutput = float(
duinototal / float(convert.Price)
) # Floats the CurrencyPrice variable (Due to it being a string on the output) and floats the overall thing.
print("You would have", finaloutput, "amount of", ID, "\n")
def calculationfrom():
coinamount = float(input("How many coins do you have?"))
cointotal = float(convert.Price) * coinamount
finaloutput = float(
cointotal / DuinoPrice
) # Floats the CoinTotal, Divides the CoinTotal by the DuinoPrice and floats it.
print("You would have", finaloutput, "duino-coin\n")
def nosupport():
print("Currency is not currently supported, open an issue to get it added.")
while True:
print(Fore.YELLOW + "Duino Coin Convertor")
print("")
Option = input(
Style.RESET_ALL
+ Fore.CYAN
+ "1 - Convert from Duino-Coin\n"
+ Style.RESET_ALL
+ Fore.GREEN
+ "2 - Convert to Duino-Coin\n"
+ Style.RESET_ALL
+ Fore.MAGENTA
+ "3 - Quit\n"
+ Style.RESET_ALL
)
if Option == "1":
Currency = input("What currency do you want to convert to?")
for option in values["currency_options"]:
if Currency.lower() in option["names"]:
ID = option["id"]
URL = option["url"]
response = requests.get(URL)
convert(ID)
calculationto(ID)
break
else:
nosupport()
elif Option == "2":
Currency = input("What currency do you want to convert from?")
for option in values["currency_options"]:
if Currency.lower() in option["names"]:
ID = option["id"]
URL = option["url"]
response = requests.get(URL)
convert(ID)
calculationfrom()
break
else:
nosupport()
elif Option == "3":
quit()