Ejemplo n.º 1
0
def downloadSave(): #TODO: test this
    MenuItems.shiftingGradient((0, 0, 'x')).draw()
    MenuItems.textLabel("Downloading Save", (1280 * 0.5, 720 * 0.5), (255, 255, 255), "Resources/Fonts/RPGSystem.ttf", int(30/640 * 1280), variable=False, centred=True).update()  
    MenuItems.screenFlip()
    
    page = urllib.request.urlopen(v.url + "accounts/")
    accounts = page.read()
    accounts = pickle.loads(accounts)
    
    for un, vals in accounts.items():
        if un == v.username:
            if v.password == vals["password"]:
                print(vals.keys())
                print(vals["xp"])
                if 'save' in vals.keys():
                    save = vals['save']
                    with open("Saves/Entities.save", "wb") as s:
                        #pickle.dump(save["Entities"], s)
                        s.write(save["Entities"])
                    with open("Saves/Inventory.save", "wb") as s:
                        #pickle.dump(save["Inventory"], s)
                        s.write(save["Inventory"])
                    with open("Saves/Variables.save", "wb") as s:
                        #pickle.dump(save["Variables"], s)
                        s.write(save["Variables"])
            else:
                return "PASSWORD"
    return "USERNAME"
Ejemplo n.º 2
0
def uploadSave():
    MenuItems.shiftingGradient((0, 0, 'x')).draw()
    MenuItems.textLabel("Uploading Save", (1280 * 0.5, 720 * 0.5), (255, 255, 255), "Resources/Fonts/RPGSystem.ttf", int(30/640 * 1280), variable=False, centred=True).update()  
    MenuItems.screenFlip()
    url = v.url + "senddata/"
    save = {}
    with open("Saves/Entities.save", "rb") as s:
        d = s.read()
        save["Entities"] = d
    with open("Saves/Inventory.save", "rb") as s:
        d = s.read()
        save["Inventory"] = d
    with open("Saves/Variables.save", "rb") as s:
        d = s.read()
        save["Variables"] = d
        xp = pickle.loads(d)["experience"]["Total"]
    
    payload = {'username': v.username, 'password': v.password, 'save': save, 'xp': xp}

    jpayload = json.dumps(str(payload))

    # GET
    #r = requests.get(url)

    # GET with params in URL
    #r = requests.get(url, params=payload)
    
    # POST with form-encoded data
    #r = requests.post(url, data=payload)
    
    # POST with JSON 
    
    r = requests.post(url, data=jpayload)
    
    # Response, status etc
    #print(r.text)
    print(r.status_code)