示例#1
0
def main():
    global password_file
    global journal_users
    global port

    logging.basicConfig(level=logging.INFO)
    if 'BUCKET_DIR_BASE' not in environ and 'S3_BUCKET_BASE' not in environ:
        raise ValueError(
            "Need BUCKET_DIR_BASE or S3_BUCKET_BASE in environment")

    if 'USER_TZ' in environ:
        # Running in AWS, so need to account for TZ.
        Entry.user_tz = environ['USER_TZ']

    if 'PASSWORD_FILE' in environ:
        password_file = environ['PASSWORD_FILE']

    port = 5000
    if 'PORT' in environ:
        port = int(environ['PORT'])
        logging.info("Set port to {}".format(port))

    debug = False
    if 'DEBUG' in environ:
        debug = True

    journal_users = User.users_from_password_file(password_file)
    for user in journal_users:
        user_buckets[user] = Bucket.bucket_factory(user)

    app.secret_key = urandom(12)
    app.run(debug=debug, port=port)
示例#2
0
from argparse import ArgumentParser
from time import mktime, strptime
from Entry import Entry
from Bucket import Bucket

parser = ArgumentParser()
parser.add_argument('--user', action='store', required=True)
parser.add_argument('--input_file', action='store', required=True)
args = parser.parse_args()

bucket = Bucket.bucket_factory(args.user)

with open(args.input_file, 'r') as input_file:
    file_content = input_file.read()

chunks = file_content.split('-' * 80)
for chunk in chunks:
    lines = chunk.split('\n')
    while lines and not lines[0]:
        lines.pop(0)
    while lines and not lines[-1]:
        lines.pop()

    if not lines:
        continue

    struct_time = strptime(lines[0])
    timestamp = mktime(struct_time)

    text = '\n'.join(lines[2:])