forked from mining/mining
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
55 lines (43 loc) · 1.34 KB
/
Copy path__init__.py
File metadata and controls
55 lines (43 loc) · 1.34 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import re
import os
import unicodedata
import ConfigParser
from bson import ObjectId
from datetime import datetime
from mining.settings import PROJECT_PATH
def slugfy(text):
slug = unicodedata.normalize("NFKD", text).encode("UTF-8", "ignore")
slug = re.sub(r"[^\w]+", " ", slug)
slug = "-".join(slug.lower().strip().split())
if not slug:
return None
return slug
def conf(section):
config = ConfigParser.ConfigParser()
config.read(os.path.join(PROJECT_PATH, 'mining.ini'))
_dict = {}
options = config.options(section)
for option in options:
try:
_dict[option] = config.get(section, option)
except:
_dict[option] = None
if 'sql_conn_params' in options:
import ast
_dict['sql_conn_params'] = ast.literal_eval(_dict['sql_conn_params'])
else:
_dict['sql_conn_params'] = {}
return _dict
def log_it(s, name=u"core"):
with open("/tmp/openmining-{}.log".format(name), "a") as log:
msg = u"{} => {}\n".format(datetime.now(), s)
log.write(msg.encode('utf-8'))
def parse_dumps(obj):
if isinstance(obj, datetime):
return str(obj.strftime("%Y-%m-%d %H:%M:%S"))
if isinstance(obj, ObjectId):
return str(obj)
return json.JSONEncoder.default(obj)