예제 #1
0
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)
예제 #2
0
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)
예제 #3
0
def batchsendmessage(subject):
    try:
        cred = credentials.Certificate('firebase/fbsacckey.json')
        default_app = firebase_admin.initialize_app(
            cred, {"databaseURL": "https://fbserv-36b3e.firebaseio.com"})
    except:
        print("firebase could not be initialized")
        return
    sentlog = db.reference("sentlog").get()
    if sentlog:
        print("sentlog fetched")
    else:
        print("using local sentlog")
        sentlog = read_json_from_file("outbox/sentlog.json", {})
    recipients = db.reference("titled").get()
    if recipients:
        lichuser = environ.get("LICHUSER", "lishadowapps")
        lichpass = environ.get("LICHPASS", "")
        print("sending message from {}".format(lichuser))
        lila2 = login(lichuser, lichpass)
        if not lila2:
            print("fatal, could not obtain login")
            return
        usernames = []
        alreadysent = 0
        for recipient in recipients:
            username = recipient["username"]
            sentloguser = sentlog.get(username, {})
            if subject in sentloguser:
                alreadysent += 1
            else:
                usernames.append(username)
        print("already sent {}".format(alreadysent))
        print("total recipients {}, available recipients {}".format(
            len(recipients), len(usernames)))
        message = read_string_from_file("outbox/message.txt", "Message.")
        #print("message: {}".format(message))
        random.shuffle(usernames)
        time.sleep(5)
        for username in usernames:
            print("sending to {}".format(username))
            if not (username in sentlog):
                print("adding {} to sentlog".format(username))
                sentlog[username] = {}
            result = sendmessage(username, subject, message, lila2)
            print("delivery result {}".format(result.name))
            if result == MESSAGE_RESULT.MESSAGE_DECLINED:
                sentlog[username][subject] = True
            elif result == MESSAGE_RESULT.MESSAGE_DELIVERED:
                sentlog[username][subject] = True
            elif (result == MESSAGE_RESULT.MESSAGE_FAILED) or (
                    result == MESSAGE_RESULT.MESSAGE_FATAL):
                print("cannot deliver more messages")
                break
        write_json_to_file("outbox/sentlog.json", sentlog)
        db.reference("sentlog").set(sentlog)
        print("messages delivered ok")
    else:
        print("fatal, no recipients")
        return
예제 #4
0
#########################################################

print("versioning assets")

allhtmls = []

for htmldir in HTML_DIRS:
    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):
예제 #5
0
from utils.misc import read_string_from_file
from json import dumps

fentest = read_string_from_file("fentest.txt", "")


def simplehash(fen, range):
    m = 1
    sum = 0
    for c in fen:
        sum += m * ord(c)
        m += 1
    return str(sum % range)


counts = {}

lines = fentest.split("\n")
print(len(lines))
for line in lines:
    parts = line.split(" ")
    fen = parts[0] + parts[1] + parts[2]
    h = simplehash(fen, 20)
    if h in counts:
        counts[h] += 1
    else:
        counts[h] = 1

print(dumps(counts, indent=2))
예제 #6
0
import re

from utils.misc import read_string_from_file, write_json_to_file

ecotxt = read_string_from_file("eco.txt", "")

pattern = re.compile("([^\s]+)\s+\"(.*?)\"(.*)")

i = 0

lines = []

for line in ecotxt.split("\n"):
    match = pattern.match(line)
    if match:
        code = match.group(1)
        name = match.group(2)
        line = match.group(3)
        if "1." in line:
            for moveno in range(20):
                line = line.replace("{}.".format(moveno), "")
            line = line.replace("\r", "")
            line = line.replace("*", "")
            parts = line.split(" ")
            moves = []
            for part in parts:
                if not (part == ""):
                    moves.append(part)
            lines.append([code, name, " ".join(moves)])

write_json_to_file("eco.json", lines)
예제 #7
0
def smileyeditor():
    reqlog(request)
    return read_string_from_file("smileyeditor.html", "smileyeditor")
예제 #8
0
def createtourney():
    reqlog(request)
    return read_string_from_file("createtourney.html", "createtourney")
예제 #9
0
def games():
    reqlog(request)
    return read_string_from_file("games.html", "games")
예제 #10
0
def tourneys():
    reqlog(request)
    return read_string_from_file("tourneys.html", "tourneys")