-
Notifications
You must be signed in to change notification settings - Fork 4
/
importer.py
40 lines (30 loc) · 1.1 KB
/
importer.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Fetcher script
Created by: Rui Carmo
License: MIT (see LICENSE for details)
"""
import os, sys, json, time, logging, logging.config
# Make sure our bundled libraries take precedence
sys.path.insert(0,os.path.join(os.path.dirname(os.path.abspath(__file__)),'lib'))
import config, utils, markup.opml
# read configuration file
config.settings = utils.get_config(os.path.join(utils.path_for('etc'),'config.json'))
# Set up logging
logging.config.dictConfig(dict(config.settings.logging))
log = logging.getLogger()
# load modules
import models, controllers
models.setup()
if __name__ == "__main__":
log.info("Starting importer.")
fc = controllers.FeedController()
uc = controllers.UserController()
user = uc.get_user('default')
feeds = markup.opml.parse_file(sys.argv[1])
start = time.time()
for f in feeds:
feed = fc.add_feed(f['xmlUrl'], title = f['title'], site_url = f['htmlUrl'])
uc.add_feed_to_group(user, feed, uc.get_group(f['group']))
log.info("%d feeds imported in %fs" % (len(feeds), time.time() - start))