38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import requests, gi
|
|
gi.require_version('Gtk', '3.0')
|
|
from gi.repository import Gtk, Gio, Gdk
|
|
|
|
import re
|
|
from os import path
|
|
|
|
def get_exchange_rate():
|
|
try:
|
|
assert False
|
|
return requests.get("https://api.exchangeratesapi.io/latest?base=AUD&symbols=JPY", timeout=10).json()['rates']['JPY']
|
|
except:
|
|
return 76.15
|
|
|
|
def msgBox(title, text, form = Gtk.MessageType.WARNING):
|
|
msgbox = Gtk.MessageDialog(app.window, 0, form, Gtk.ButtonsType.OK, title)
|
|
msgbox.format_secondary_text(text)
|
|
response = msgbox.run()
|
|
msgbox.destroy()
|
|
return response
|
|
|
|
def rmatch(pattern, string):
|
|
return re.match(pattern, string) != None
|
|
|
|
def readSettings():
|
|
global settings
|
|
if not path.isfile(settingsLocation + "config.json"):
|
|
os.makedirs(settingsLocation, 0o755)
|
|
open(settingsLocation + "config.dat", 'x')
|
|
try:
|
|
settings = pickle.load(open(settingsLocation + "config.dat", 'rb'))
|
|
except:
|
|
MsgBox("Error", "Failed to load settings. The default settings will be used instead.")
|
|
settings = {"setting":"value", "save database": True} #indent me when releasing!
|
|
|
|
def writeSettings():
|
|
global settings
|
|
pickle.dump(settings, open(settingsLocation + "config.dat", 'wb'))
|