-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.py
93 lines (77 loc) · 3.52 KB
/
common.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
"""This module provides a function for shipping logs to Airtable."""
import os
import time
import cloudinary
from airtable import Airtable
from documentcloud import DocumentCloud
airtab_intakes = Airtable(os.environ['jail_scrapers_db'],
table_name='intakes',
api_key=os.environ['AIRTABLE_API_KEY'])
airtab_log = Airtable(os.environ['log_db'],
table_name='log',
api_key=os.environ['AIRTABLE_API_KEY'])
airtab_daily = Airtable(os.environ['jail_scrapers_db'],
table_name='daily stats',
api_key=os.environ['AIRTABLE_API_KEY'])
airtab_archive_intakes = Airtable(os.environ['jails_archive_db'],
table_name='intakes',
api_key=os.environ['AIRTABLE_API_KEY'])
airtab_tweets = Airtable(os.environ['botfeldman89_db'],
table_name='scheduled_tweets',
api_key=os.environ['AIRTABLE_API_KEY'])
cloudinary.config(cloud_name='bfeldman89',
api_key=os.environ['CLOUDINARY_API_KEY'],
api_secret=os.environ['CLOUDINARY_API_SECRET'])
dc = DocumentCloud(username=os.environ['MUCKROCK_USERNAME'],
password=os.environ['MUCKROCK_PW'])
muh_headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'}
county_jails = [('Madison', 'mcdc'),
('Pearl River', 'prcdf'),
('Lee', 'lcdc'),
('Hinds', 'hcdc'),
('Kemper', 'kcdc'),
('Tunica', 'tcdc'),
('Clay', 'ccdc'),
('Adams', 'acdc'),
('Jasper', 'jcj'),
('Jackson', 'jcadc'),
('Jones', 'jcdc'),
('Calhoun', 'ccj')]
my_funcs = {'acdc_scraper': 'recZdPJHytCXB3v7C',
'ccdc_scraper': 'recDAFRGM4gkPhHEO',
'hcdc_scraper': 'rec3CEVirsVhbogFp',
'jcadc_scraper': 'recVgj1nGL6H79bNZ',
'jcj_scraper': 'recQIKW9Ky2K5s9sS',
'jcdc_scraper': 'recsDwt7wzD03PcKE',
'kcdc_scraper': 'recVkA9ZjjDC7WHMl',
'lcdc_scraper': 'recqvYm2sWOVXVFwE',
'mcdc_scraper': 'rec2kqwh9Nj8jyeqW',
'prcdf_scraper': 'recsbEUfUO9WjXi8I',
'tcdc_scraper': 'rec19KIgPSPYX8dyG',
'ccj_scraper': 'recvKVXiBNnFOVWt6',
'fix_charges_to_by_lines': 'rechl6T1MRB4EK9NF',
'get_all_intake_deets': 'recz3G21RAFoebeqe',
'get_charges_from_recent_text': 'rec1QQGOdKrliYy52',
'get_full_text': 'recszZqgqyMZbrZWA',
'get_pixelated_mug': 'rece3aWHAWx2dAv09',
'parse_charge_1': 'recndlqiBduVHEekv',
'remove_weird_character': 'recDlfvTxn2YQyJ7V',
'retry_getting_mugshot': 'rechPDYn5Koib8fjq',
'update_summary': 'reczRWJZM7KIz1LRd',
'get_dor_if_possible': 'recFMBytEdFfWEghZ',
'pdf_to_dc': 'recqUaIfPApOsw6SB',
'web_to_pdf': 'recFWboNnGFfVBnnS'}
def wrap_from_module(module):
def wrap_it_up(t0, new=None, total=None, function=None):
this_dict = {
'module': module,
'function': function,
'_function': my_funcs[function],
'duration': round(time.time() - t0, 2),
'total': total,
'new': new
}
airtab_log.insert(this_dict, typecast=True)
return wrap_it_up