buypeeb/buypeeb.py

92 lines
2.9 KiB
Python
Executable File

#!/usr/bin/env python
# <one line to give the program's name and a brief idea of what it does.>
# Copyright (C) 2020 lynnesbian
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import requests, gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gio, Gdk
import functions
from listing import YahooAuctionsItem
from settings import BuypeebSettings
import json, sys
from os import path
isWindows = sys.platform.startswith('win')
if isWindows:
settingsLocation = path.join(os.getenv("APPDATA"), "Lynnear Software", "bypeeb")
else:
settingsLocation = path.expanduser("~/.config/Lynnear Software/buypeeb/") # dotfiles in ~ need to die. begone dot
# print("Getting JPY/AUD exchange rate...")
rate = functions.get_exchange_rate()
x = YahooAuctionsItem("My cool product", "peeb.us")
print(f"Bidding for item \"{x.name}\" started at {x.start_date} and will end at {x.end_date}. Current price is {x.price_jpy()}, or {x.price_aud()}.")
class BuypeebApp:
def __init__(self):
self.app = Gtk.Application.new('com.lynnearsoftware.buypeeb', 0)
self.app.connect('startup', self.startup)
self.app.connect('activate', self.activate)
self.app.connect('shutdown', self.shutdown)
self.window = None
self.settings = BuypeebSettings(settingsLocation)
def run(self, argv):
self.app.run(argv)
def startup(self, app):
builder = Gtk.Builder()
builder.add_from_string(open(path.join(path.dirname(__file__), "ui/main.glade"), 'r').read())
builder.connect_signals(self)
wndMain = builder.get_object('wndMain')
self.window = wndMain
app.add_window(self.window)
self.settings.load()
def activate(self, app):
self.window.show_all()
def shutdown(self, app):
self.settings.save()
self.app.quit()
def msgBox(self, title, text, form = Gtk.MessageType.WARNING):
msgbox = Gtk.MessageDialog(self.window, 0, form, Gtk.ButtonsType.OK, title)
msgbox.format_secondary_text(text)
response = msgbox.run()
msgbox.destroy()
return response
def btnAddClicked(self, widget):
self.msgBox("good job", "succkeess")
def btnQuitClicked(self, widget):
prompt = Gtk.MessageDialog(self.window, 0, Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK_CANCEL, "Really quit?")
prompt.format_secondary_text("Are you sure you want to quit buypeeb?")
response = prompt.run()
if response:
self.shutdown(self)
if __name__ == '__main__':
app = BuypeebApp()
app.run(sys.argv)