def toenv(): fbsacckey = read_string_from_file("firebase/fbsacckeyorig.json","{}") chunks = chunkstring(enc(fbsacckey), CHUNK_SIZE) bat = "" heroku_conn = heroku3.from_key("") app = heroku_conn.app("fbserv") appconfig = app.config() print("heroku app", app, appconfig) i = 0 for chunk in chunks: varname = "{}_{}".format(ENV_NAME, i) decchunk = chunk.decode() print("setting config var", i, varname, decchunk) appconfig[varname] = decchunk bat += "set {}={}\n".format(varname, decchunk) i+=1 write_string_to_file("s/toenv.bat", bat) print("new app config", appconfig)
def toenv(): fbsacckey = read_string_from_file("firebase/fbsacckeyorig.json", "{}") chunks = chunkstring(enc(fbsacckey), CHUNK_SIZE) bat = "" heroku_conn = heroku3.from_key(os.environ.get("FBSERV_TOKEN")) app = heroku_conn.app("fbserv") appconfig = app.config() print("heroku app", app, appconfig) i = 0 for chunk in chunks: varname = "{}_{}".format(ENV_NAME, i) decchunk = chunk.decode() print("setting config var", i, varname, decchunk) appconfig[varname] = decchunk bat += "set {}={}\n".format(varname, decchunk) i += 1 write_string_to_file("s/toenv.bat", bat) appconfig["NOTOURNEY"] = "1" appconfig["NOCHAT"] = "1" bottokens = read_string_from_file("conf/bottokens.txt", "") print("setting bot tokens", bottokens) appconfig["BOT_TOKENS"] = bottokens print("new app config", appconfig)
def fromenv(): content = "" for i in range(100): try: chunk = os.environ["{}_{}".format(ENV_NAME, i)] cd = base64.b64decode(chunk).decode() content += cd except: break write_string_to_file("firebase/fbsacckey.json", content) print("written content", content)
def sendmessage(username, subject, message, lila2): url = "https://lichess.org/inbox/new?username={}".format(username) print("sending to {}\nsubject: {}\nmessage: {}\nurl: {}".format( username, subject, message, url)) try: res = http.request("POST", url, headers={"cookie": "lila2={}".format(lila2)}, fields={ "subject": subject, "text": message }) print("message delivery status", responses[res.status]) try: #content = res.data.decode("utf-8") content = "{}".format(res.data) write_string_to_file("outbox/sendmessagecontent.txt", content) write_string_to_file("outbox/sendmessagecontent.html", content) if '<p class="error">' in content: print("message declined") return MESSAGE_RESULT.MESSAGE_DECLINED if '<div class="thread_message_body">' in content: print("message delivered OK") return MESSAGE_RESULT.MESSAGE_DELIVERED print("message delivery failed") return MESSAGE_RESULT.MESSAGE_FAILED except: print("fatal, could not process response body") print(res.info()) return MESSAGE_RESULT.MESSAGE_FATAL except: print("fatal, http request failed") return MESSAGE_RESULT.MESSAGE_FATAL
["download", "Image file download temporary directory."], ["drive", "Drive temporary directory."]] for readmedir in README_DIRS: dir = readmedir[0] desc = readmedir[1] #print("removing", dir) try: rmtree(dir) except: #print("nothing to remove") pass #print("creating dir", dir) create_dir(dir, False) #print("creating readme", desc) write_string_to_file(os.path.join(dir, "ReadMe.md"), desc) BROWSER_CONFIG_PATH = "cache/browserconfig.yml" if noselenium: browser = None else: browser = webdriver.Chrome() CHECK_DIRS = [os.path.join("static", "css")] dir_dicts = {} for dir in CHECK_DIRS: dir_dicts[dir] = dir_listing_as_dict(dir)
files = dir_listing_as_list(htmldir) for file in files: if file["ext"] == "html": allhtmls.append([htmldir, file]) for file in allhtmls: path = file[0] + "/" + file[1]["name"] content = read_string_from_file(path, "") newlines = [] changed = False for line in content.splitlines(): newline = line for delim in VERSION_DELIMS: if delim["find"] in line: fullname = firstbetween(line, delim["left"], delim["right"]) propername = firstbetween(fullname, '', '?') print("examining", propername) if propername in VERSIONED_FILES: print("*", propername, "is versioned") mtime = "{:.0f}".format(stat(propername).st_mtime) newfullname = propername + "?ver=" + mtime newline = line.replace(fullname, newfullname) if not (newline == line): print("-->", newfullname, path) changed = True newlines.append(newline) if changed: newcontent = "\n".join(newlines) print("------\nupdating {}\n------".format(path)) write_string_to_file(path, newcontent)
def serverlogic(reqobj): resobj = reqobj try: if "kind" in reqobj: kind = reqobj["kind"] if kind == "serializeconfig": jsontext = json.dumps(reqobj["data"], indent=2) write_string_to_file("schemaconfig.json", jsontext) resobj = {"kind": "configsaved", "size": len(jsontext)} elif kind == "storecloudconfig": try: data = reqobj["data"] jsontext = json.dumps(data, indent=2) db.reference("schemaconfig").set(data) resobj = {"kind": "configsaved", "size": len(jsontext)} except: print_exc(file=sys.stderr) elif kind == "retrievecloudconfig": try: data = db.reference("schemaconfig").get() resobj = {"kind": "setcloudconfig", "schemaconfig": data} except: print_exc(file=sys.stderr) elif kind == "updateuserdetails": try: uid = reqobj["uid"] userdetails = reqobj["userdetails"] displayname = userdetails["displayname"] photourl = userdetails["photourl"] if not (displayname == ""): auth.update_user(uid, display_name=displayname) if not (photourl == ""): auth.update_user(uid, photo_url=photourl) else: photourl = None auth.update_user(uid, photo_url=None) msg = "Updated user [{}] with display name [{}] and photo url [{}].".format( uid, displayname, photourl) print(msg) resobj = {"kind": "alert", "reload": True, "data": msg} except: resobj = { "kind": "alert", "data": "There was a problem updating user details." } print_exc(file=sys.stderr) elif kind == "saveupload": try: filename = reqobj["filename"] savefilename = reqobj["savefilename"] savepath = reqobj["savepath"] blobpath = "uploads/{}".format(savefilename) print("upload", blobpath) blob = bucket.blob(blobpath) blob.upload_from_filename(savepath) blob.make_public() medialink = blob.media_link resobj = { "success": True, "filename": filename, "savefilename": savefilename, "savepath": savepath, "blobpath": blobpath, "medialink": medialink } except: print_exc(file=sys.stderr) resobj = { "success": False, "status": "could not upload file" } elif kind == "getupload": try: filepath = reqobj["filepath"] filename = reqobj["filename"] blobpath = "uploads/{}".format(filename) print("download", blobpath) blob = bucket.blob(blobpath) blob.download_to_filename(filepath) resobj = { "success": True, "filename": filename, "filepath": filepath, "blobpath": blobpath } except: resobj = { "success": False, "status": "could not download file" } except: print_exc(file=sys.stderr) return resobj