Пример #1
0
in_file = argv[1]
out_file = in_file + '.json'
if len(argv) > 2:
    out_file = argv[2]

###########################################################################
# check input file exists
if not os.path.exists(in_file):
    print 'File not found: ', in_file
    exit()

###########################################################################
# read in bsf
post = dict()

# note mode 'rU', U allows universal newlines
with open(in_file, 'rU') as file:
    post['url'] = remove_newlines(file.readline())
    post['date'] = remove_newlines(file.readline())
    post['author'] = remove_newlines(file.readline())
    post['tags'] = remove_newlines(file.readline()).split(' ')
    post['title'] = read_until_double_newline(file)
    post['blurb'] = read_until_double_newline(file)
    post['text'] = read_until_eof(file)

###########################################################################
# dump json to a file
with open(out_file, 'w') as file:
    file.write(json.dumps(post))
    file.write('\n')
Пример #2
0
if len(argv) < 3:
    print 'Usage:', argv[0], '{index_file} {post_file}'
    exit()

###########################################################################
# check post file exists
post_filename = argv[2]
if not os.path.exists(post_filename):
    print 'File not found: ',post_filename
    exit()

###########################################################################
# read in post
post = dict()
with open(post_filename,'rU') as file:
    post = json.loads(read_until_eof(file))

# remove text section
post.pop('text')

###########################################################################
# create or read in the index
index_filename = argv[1]
index = dict(posts=[],posts_by_url={},posts_by_date={},posts_by_tag={},posts_by_filename={},posts_by_author={},prev={},next={})
if os.path.exists(index_filename):
    with open(index_filename,'rU') as file:
        index = json.loads(read_until_eof(file))

###########################################################################
# check that post filename/url doesn't already exist
if index['posts_by_url'].has_key(post['url']):
Пример #3
0
if len(argv) < 3:
    print 'Usage:', argv[0], '{index_file} {post_file}'
    exit()

###########################################################################
# check post file exists
post_filename = argv[2]
if not os.path.exists(post_filename):
    print 'File not found: ', post_filename
    exit()

###########################################################################
# read in post
post = dict()
with open(post_filename, 'rU') as file:
    post = json.loads(read_until_eof(file))

# remove text section
post.pop('text')

###########################################################################
# create or read in the index
index_filename = argv[1]
index = dict(posts=[],
             posts_by_url={},
             posts_by_date={},
             posts_by_tag={},
             posts_by_filename={},
             posts_by_author={},
             prev={},
             next={})
Пример #4
0
in_file = argv[1]
out_file = in_file + '.json'
if len(argv) > 2:
    out_file = argv[2]

###########################################################################
# check input file exists
if not os.path.exists(in_file):
    print 'File not found: ',in_file
    exit()

###########################################################################
# read in bsf
post = dict()

# note mode 'rU', U allows universal newlines
with open(in_file,'rU') as file:
    post['url'] = remove_newlines(file.readline())
    post['date'] = remove_newlines(file.readline())
    post['author'] = remove_newlines(file.readline())
    post['tags'] = remove_newlines(file.readline()).split(' ')
    post['title'] = read_until_double_newline(file)
    post['blurb'] = read_until_double_newline(file)
    post['text'] = read_until_eof(file)

###########################################################################
# dump json to a file
with open(out_file,'w') as file:
    file.write(json.dumps(post))
    file.write('\n')