Beispiel #1
0
 def __init__(self, username, password, method='kmeans'):
     auth = ClientAuthMethod(username, password)
     self.reader = GoogleReader(auth)
     self.reader.buildSubscriptionList()
     self.categories = self.reader.getCategories()
     self.corpus = Corpus()
     self.method = method
    def test_transaction_add_feed_tags(self):
        ca = ClientAuthMethod(username, password)
        reader = GoogleReader(ca)
        container = SpecialFeed(reader, ReaderUrl.READING_LIST)
        container.loadItems()

        tags = ['test-transaction%s' % x for x in range(5)]
        feed_1 = container.items[0]

        reader.beginAddItemTagTransaction()
        for tag in tags:
            reader.addItemTag(feed_1, 'user/-/label/' + tag)
        reader.commitAddItemTagTransaction()

        #reload now
        container.clearItems()
        container.loadItems()
        feed_2 = container.items[0]

        # figure out if all tags were returned
        tags_exist = [
            any(map(lambda tag: tag in x, tags))
            for x in feed_2.data['categories']
        ]
        tag_exist_count = sum([1 for x in tags_exist if x])
        self.assertEqual(5, tag_exist_count)
Beispiel #3
0
    def test_loading_item_count(self):
        ca = ClientAuthMethod(username, password)
        reader = GoogleReader(ca)
        container = SpecialFeed(reader, ReaderUrl.READING_LIST)
        container.loadItems(loadLimit=5)

        self.assertEqual(5, len(container.items))
        self.assertEqual(5, container.countItems())
Beispiel #4
0
    def test_marking_read(self):
        ca = ClientAuthMethod(username, password)
        reader = GoogleReader(ca)
        container = SpecialFeed(reader, ReaderUrl.READING_LIST)
        container.loadItems()

        feed_item = container.items[0]
        self.assertTrue(feed_item.markRead())
        self.assertTrue(feed_item.isRead())
Beispiel #5
0
    def test_reading_list_exists(self):
        ca = ClientAuthMethod(username, password)
        reader = GoogleReader(ca)
        reader.makeSpecialFeeds()
        feeds = reader.getFeedContent(
            reader.getSpecialFeed(ReaderUrl.READING_LIST))

        self.assertEqual(dict, type(feeds))

        list_match = re.search('reading list in Google Reader', feeds['title'])
        self.assertTrue(list_match)
Beispiel #6
0
    def test_subscribe_unsubscribe(self):
        ca = ClientAuthMethod(username, password)
        reader = GoogleReader(ca)

        slashdot = 'feed/http://rss.slashdot.org/Slashdot/slashdot'

        #unsubscribe always return true; revert feedlist state
        self.assertTrue(reader.unsubscribe(slashdot))

        # now subscribe
        self.assertTrue(reader.subscribe(slashdot))

        # wait for server to update
        time.sleep(1)
        reader.buildSubscriptionList()

        # test subscribe successful
        self.assertIn(slashdot, [x.id for x in reader.getSubscriptionList()])
def main():
    if len(sys.argv) <= 1 or len(sys.argv) > 3:
        print("Usage: %s username [password]" % (sys.argv[0]))
        return 1

    username = sys.argv[1]
    if len(sys.argv) == 2:
        sys.stderr.write('Password for %s: ' % username)
        password = raw_input()
    else:
        password = sys.argv[2]

    auth = ClientAuthMethod(username, password)
    reader = GoogleReader(auth)

    root = ET.Element('opml')
    head = ET.SubElement(root, 'head')
    ET.SubElement(head, 'title').text = \
        '%s subscriptions in Google Reader' % username
    body = ET.SubElement(root, 'body')

    category_els = {}

    reader.buildSubscriptionList()
    for feed in reader.getSubscriptionList():
        if feed.getCategories():
            for category in feed.getCategories():
                # Create category element
                if not category.id in category_els:
                    category_el = ET.SubElement(body, 'outline')
                    category_el.set('text', category.label)
                    category_el.set('title', category.label)
                    category_els[category.id] = category_el
                make_feed_el(feed, category_els[category.id])
        else:
            make_feed_el(feed, body)

    tree = ET.ElementTree(root)
    tree.write(sys.stdout, xml_declaration=True)
    def test_add_remove_single_feed_tag(self):
        ca = ClientAuthMethod(username, password)
        reader = GoogleReader(ca)
        container = SpecialFeed(reader, ReaderUrl.READING_LIST)
        container.loadItems()

        tag_name = 'test-single-tag'
        feed_1 = container.items[0]

        # assert tag doesn't exist yet
        self.assertFalse(
            any([tag_name in x for x in feed_1.data['categories']]))

        # add tag
        reader.addItemTag(feed_1, 'user/-/label/' + tag_name)

        #reload now
        container.clearItems()
        container.loadItems()
        feed_2 = container.items[0]

        # assert tag is in new
        self.assertTrue(any([tag_name in x
                             for x in feed_2.data['categories']]))

        # remove tag
        reader.removeItemTag(feed_2, 'user/-/label/' + tag_name)

        #reload now
        container.clearItems()
        container.loadItems()
        feed_3 = container.items[0]

        # assert tag is removed
        self.assertFalse(
            any([tag_name in x for x in feed_3.data['categories']]))
Beispiel #9
0
        subscription.items = []
        subscription.itemsById = {}
        subscription.loadMoreItems(loadLimit=load)
    except Exception:
        logging.warning(sys.exc_info()[0])
        print "Continuing..."
        sys.exc_clear()
        loadMoreUntilSuccessful(subscription, load)


couch = couchdb.Server('http://localhost:5984')
try:
    db = couch[db_name]
except Exception:
    db = couch.create(db_name)
auth = ClientAuthMethod(username, password)
reader = GoogleReader(auth)
ll = 100
reader.buildSubscriptionList()
l = reader.getSubscriptionList()

for li in l:
    print li.title.encode('ascii', 'xmlcharrefreplace')
    loadUntilSuccessful(li, ll)
    while li.lastLoadLength > 0:
        bulk_upload = []
        for i in li.getItems():
            doc = {}
            doc = i.data
            if len(li.categories) > 0:
                doc["label"] = li.categories[0].label
Beispiel #10
0
 def test_reader_user_info(self):
     ca = ClientAuthMethod(username,password)
     reader = GoogleReader(ca)
     info = reader.getUserInfo()
     self.assertEqual(dict, type(info))
     self.assertEqual(firstname, info['userName'])
Beispiel #11
0
 def test_reader(self):
     ca = ClientAuthMethod(username,password)
     reader = GoogleReader(ca)
     self.assertNotEqual(reader, None)
Beispiel #12
0
 def test_ClientAuthMethod_login(self):
     ca = ClientAuthMethod(username,password)
     self.assertNotEqual(ca, None)
Beispiel #13
0
    title = Optional(unicode, 1500, nullable=True)
    date_created = Optional(datetime, nullable=True)
    url = Optional(unicode, 1500, nullable=True)
    isread = Optional(bool, default=False)
    isstarred = Optional(bool, nullable=True)
    isshared = Optional(bool, nullable=True)
    feed = Required(Feed)


#sql_debug(True)
db.generate_mapping(create_tables=True)

GMAIL_ACCOUNT = "YOUR_GOOGLE_READER_ACCOUNT"
GMAIL_PASSWORD = "******"

auth = ClientAuthMethod(GMAIL_ACCOUNT, GMAIL_PASSWORD)
reader = GoogleReader(auth)
reader.buildSubscriptionList()
categories = reader.categories
feeds = [c.getFeeds() for c in categories]


def fetch():
    for cate in reader.categories:
        #c = [i for i in reader.categories if i.label == "IT.JIE"][0]
        for cfeeds in feeds:
            for n, i in enumerate(cfeeds):
                p = Process(target=w, args=(cate, i))
                p.start()
                p.join()
                p.terminate()