Created
June 2, 2018 11:33
-
-
Save limkopii/f67ca7444d0d664940f16732776701df to your computer and use it in GitHub Desktop.
feedly.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import csv | |
ACCESS_TOKEN = None | |
def get_response(api, parameter): | |
header = {"Authorization": ACCESS_TOKEN} | |
url = "https://cloud.feedly.com/{}?".format(api,) | |
if parameter != None: | |
url = "{0}?{1}".format(url, parameter) | |
try: | |
response = requests.get(url, headers=header, verify = False, timeout=5) | |
return json.loads(response.text) | |
except Exception as e: | |
print str(e) | |
def write_row(writer, result): | |
tags = "" | |
for tag in result["deliciousTags"]: | |
try: | |
tags += "|{}".format(tag) | |
except UnicodeEncodeError as e: | |
continue | |
tags += "|" | |
if "website" in result: | |
writer.writerow([result["website"], result["subscribers"], tags]) | |
search_term = ["food", "singapore", "asia", "chickenchop","house","finance","investment","ebook","humor","funny" "apple", "tech", "mac", "windows", "microsoft", "lifehack", "minimalistic", "cats", "dogs", "whiskey", "beer", "alcohol"] | |
feeds = [] | |
for term in search_term: | |
feeds.append(get_response("/v3/search/feeds", "query={0}&count=20".format(term))['results']) | |
# write to csv files | |
output = "feedly.csv" | |
with open(output, "wb") as csvfile: | |
writer = csv.writer(csvfile, delimiter=",", quotechar="\"") | |
writer.writerow(["website","subscribers","tags"]) | |
for feed in feeds: | |
for r in feed: | |
write_row(writer, r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment