-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathutils.py
More file actions
27 lines (20 loc) · 669 Bytes
/
utils.py
File metadata and controls
27 lines (20 loc) · 669 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# -*- coding: utf-8 -*-
"""
Purpose : Different Helpers for the module.
"""
import codecs
import json
def read_list(file_path):
with codecs.open(file_path, "r", encoding='utf-8') as f:
l = [line.strip() for line in f.readlines()]
return l
def write_to_json(json_file_path, data):
""" add data (one item per line) to json file """
with codecs.open(json_file_path, "a", encoding='utf-8') as f:
f.write("{}\n".format(json.dumps(data)))
def join_keywords(l):
""" join a list of keywords with '+' for BingSearch """
return u'+'.join(l)
def write_file(file, file_path):
with open(file_path, 'w') as f:
f.write(file)