Skip to content

Commit 6451a05

Browse files
committed
Some work on periodic emails
1 parent b2c94f5 commit 6451a05

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import sqlalchemy
3+
import itertools
4+
5+
from datapackage_pipelines.wrapper import ingest, spew
6+
from datapackage_pipelines.utilities.resources import PROP_STREAMING
7+
8+
if __name__ == '__main__':
9+
params, dp, res_iter = ingest()
10+
11+
dp['resources'].append(
12+
dict(
13+
name='subs',
14+
path='.',
15+
schema=dict(
16+
fields=[
17+
dict(name='email', type='string'),
18+
dict(name='items', type='array')
19+
]
20+
)
21+
)
22+
)
23+
dp['resources'][0][PROP_STREAMING] = True
24+
25+
e = sqlalchemy.create_engine(os.environ['PRIVATE_DATABASE_URL'])
26+
r = map(dict,
27+
e.execute("""
28+
select email, title, url, properties
29+
from items join lists on(items.list_id=lists.id)
30+
join users on(lists.user_id=users.id)
31+
where lists.name='searches'
32+
order by email
33+
"""
34+
))
35+
36+
r = (dict(email=email, items=list(items))
37+
for email, items in itertools.groupby(r, lambda x: x['email']))
38+
spew(dp, [r])
39+
40+
41+
42+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
emails:
2+
title: Send periodic emails
3+
4+
pipeline:
5+
- run: fetch_subscriptions
6+
- run: sample
7+
- run: send_emails
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from datapackage_pipelines.wrapper import process
2+
3+
import logging
4+
import requests
5+
6+
7+
def process_row(row, *_):
8+
logging.info('ROW: %r', row)
9+
10+
if __name__ == '__main__':
11+
process(process_row=process_row)
12+
13+

0 commit comments

Comments
 (0)