Ejemplo n.º 1
0
 def check_config(self):
     cfg_path = "configs/{}/dlc.json".format(self.selected_game)
     if dataIO.is_valid_json(cfg_path) is False:
         self.owns = False
         QMessageBox.warning(self, "Warning", "'dlc.json' from '{}' have errors or not found, "
                                              "functionality has been limited".format(self.selected_game))
     else:
         self.owns = {}
         self.dlc = dataIO.load_json(cfg_path)
Ejemplo n.º 2
0
def update_configs(is_save, cfg_list):
    if is_save in (0, 1):
        for cfg in cfg_list:
            check_path(cfg)
            response_status, response = get_response_result(github_link + cfg)
            if response_status:
                remote_cfg = literal_eval(response.text)
                if dataIO.is_valid_json(cfg) or os.path.exists(cfg):
                    dataIO.save_json(cfg, remote_cfg)
    if is_save in (1, 3):
        text = str({
            "answer_updates": is_save == 3,
            "update_on_start": is_save == 1
        })
        with open(update_config_name, "w") as f:
            f.write(text)
Ejemplo n.º 3
0
import praw
import secret
import re
import template as temp
from dataIO import dataIO

if dataIO.is_valid_json("settings.json"):
    settings = dataIO.load_json("settings.json")
    print("loaded json")
else:
    settings = {"maeve_cash": 00.00}
    print("couldn't load json")

footer = temp.footer  # this is for any announcements, etc

# scoping smh my head

pattern = re.compile(
    r"(?i)maeve,? ?not,? ?(?:\"|\'|) ?(?:me?ai?y?u?ve|mayve?) ?(?:\"|\'|)")
misspell = re.compile(r"(?i)(?:me?ai?y?u?ve|mayve?)")


def lobot(r, sub):
    nothings = 0
    monies = settings["maeve_cash"]
    last_run = settings.get("maeve_last_run")
    print("now at ${}, last run was {} \n \n \n".format(monies, last_run))
    for comment in r.subreddit(sub).comments(limit=9999):
        # somehow comment.author.name isn't working
        if str(comment.author) == "REEvie_bot":
            continue  # skip this iteration and move on to next comment
Ejemplo n.º 4
0
    def __init__(self, selected_game, owns_list, parent=None):
        # Setup UI
        QDialog.__init__(self, parent, flags=Qt.Window)
        Ui_SecondWindow.__init__(self)
        self.ui = Ui_SecondWindow()
        self.ui.setupUi(self)

        self.owns = owns_list  # From main window

        # Checking files
        cfg_path = "configs/{}".format(selected_game)
        dealers_path = "{}/dealers.json".format(cfg_path)
        agencies_path = "{}/agencies.json".format(cfg_path)
        if dataIO.is_valid_json(dealers_path) is False:
            self.dealers = False
            self.ui.dealer_edit.setEnabled(False)
            self.ui.dealer_add.setEnabled(False)
            self.ui.dealer_add_all.setEnabled(False)
            QMessageBox.warning(
                self, "Warning",
                "'dealers.json' from '{}' have errors or not found.\n"
                "Dealers editing has been disabled".format(selected_game))
        else:
            self.dealers = []
            self.dealers_file = dataIO.load_json(dealers_path)

        if dataIO.is_valid_json(agencies_path) is False:
            self.agencies = False
            self.ui.agency_edit.setEnabled(False)
            self.ui.agency_add.setEnabled(False)
            self.ui.agency_add_all.setEnabled(False)
            QMessageBox.warning(
                self, "Warning",
                "'agencies.json' from '{}' have errors or not found.\n"
                "Agencies editing has been disabled".format(selected_game))
        else:
            self.agencies = []
            self.agencies_file = dataIO.load_json(agencies_path)

        self.ui.garage_size.addItem("Small")
        self.ui.garage_size.addItem("Medium")
        self.ui.garage_size.addItem("Big")

        # Dealers and agencies properties
        self.da_array = {
            self.ui.dealer_add: [
                self.ui.dealer_edit, "unlocked_dealers:", "Dealership",
                self.dealers, self.check_dealers
            ],
            self.ui.agency_add: [
                self.ui.agency_edit, "unlocked_recruitments:",
                "Recruitment agency", self.agencies, self.check_agencies
            ],
        }

        # Connecting buttons
        self.ui.garages_analyze.clicked.connect(self.check_garages)
        self.ui.garage_add.clicked.connect(self.add_garage)
        self.ui.garage_add_all.clicked.connect(self.add_all_garages)
        self.ui.headquarter_change.clicked.connect(self.change_headquarter)
        self.ui.city_add.clicked.connect(self.add_city)
        self.ui.city_add_all.clicked.connect(self.add_all_cities)
        self.ui.dealer_add.clicked.connect(self.da_clicked)
        self.ui.dealer_add_all.clicked.connect(self.add_all_dealers)
        self.ui.agency_add.clicked.connect(self.da_clicked)
        self.ui.agency_add_all.clicked.connect(self.add_all_agencies)

        if self.owns:
            self.fill_list(self.dealers, self.dealers_file)
            self.fill_list(self.agencies, self.agencies_file)
        # Checking save-file
        self.check_cities()
        self.check_dealers()
        self.check_agencies()
Ejemplo n.º 5
0
def main(r, qui, sub, filterfun, footer=defaultfooter, jsonbackup={}, *misc):
    '''
    template function for comment checking and looping.

    iterates through last 7999 comments of sub. if their author is not reevie_bot and was made after last run, call fun and add returned value to reply, then reply if reply is not empty

    Args

    r - val from login()
    qui - str (reevie, maeve, grohk)
    sub - which subreddit to run the bot in
    fun - function for bot logic. must return string, which will be added to reply (no reply if end up empty)

    Kwargs

    footer - text to put at the bottom of the comment. value of template.defaultfooter by default
    jsonbackup - dict to replace json when it's unloadable. {} by default.
    misc - additional args.
    '''

    import praw
    from dataIO import dataIO

    # defaults = 'praw dataIO'.split(" ") # the prereqs we need for every bot
    # rd = {} # requisite dictionary
    # for i in defaults:
    #     rd[i] = importlib.import_module(i) # import every module we need
    # # if using reqdict replace module names with rd['modulename']

    login(qui)  # log us in

    if dataIO.is_valid_json(
            "settings.json"):  # check file integrity then load it
        main.settings = dataIO.load_json("settings.json")
        print(main.settings)
    else:
        main.settings = jsonbackup  # use our backup dict if our file is f****d
        print("couldn't load json")

    # init
    nothings = 0
    reply = ''

    # main
    main.last_run = main.settings.get("{}_last_run".format(qui))
    for comment in r.subreddit(sub).comments(
            limit=7999):  # change to 9999 later

        reply = ''

        if str(comment.author) == "REEvie_bot":  # prevents self reply
            continue  # skip this iteration and move on to next comment

        # skip comments created before the most recent comment from the last run (prevents from replying twice to the same comment)
        if main.last_run:  # can be None if the settings file didn't exist or got corrupted
            if comment.created_utc <= main.last_run:
                print(
                    str(comment) +
                    " was already replied to, breaking loop. \n")
                break

        reply = filterfun(comment, misc)

        if reply:  # reply only if str is nonempty
            comment.reply(reply + footer)
        else:
            nothings += 1

    newest_comment = next(
        r.subreddit(sub).comments(limit=1))  # get the most recent comment
    main.settings["{}_last_run".format(
        qui
    )] = newest_comment.created_utc  # store the creation time of it as Unix timestamp
    dataIO.save_json("settings.json", main.settings)  # save to file
    print("oof: {} comments with nothing \n \n \n".format(nothings))
Ejemplo n.º 6
0
import sys
sys.path.insert(0, 'utils')

from dataIO import dataIO


test_list = []
for i in range(10):
    test_d = {'Hello':i}
    test_list.append(test_d)

if not dataIO.is_valid_json("../data/test.json"):
    print("Creating empty {}...".format("test.json"))
    dataIO.save_json("../data/test.json", [])

dataIO.save_json("../data/test.json", test_list)

json_test = dataIO.load_json("../data/test.json")

print (json_test)