Skip to content

Instantly share code, notes, and snippets.

@gmariette
Last active February 16, 2020 13:18
Show Gist options
  • Select an option

  • Save gmariette/d6f66f3f640f502c3f3d172f288ad0ea to your computer and use it in GitHub Desktop.

Select an option

Save gmariette/d6f66f3f640f502c3f3d172f288ad0ea to your computer and use it in GitHub Desktop.
import requests
import feedparser
import json
def getMediumInfo(blogPosts):
# https://github.com/kurtmckee/feedparser/issues/84
import ssl
if hasattr(ssl, '_create_unverified_context'):
ssl._create_default_https_context = ssl._create_unverified_context
# Medium token
mediumToken = "xxx"
# Set the headers
headers = {
'Authorization': "Bearer " + mediumToken,
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36'
}
# Who is behind the token ?
base_url = "https://api.medium.com/v1/"
r = requests.get(base_url+'me', headers=headers)
myUserJson = (r.json())
# Get the feed with rss parsing
newsFeed = feedparser.parse('https://medium.com/feed/@'+myUserJson['data']['username'])
# List for all the blog posts
for entry in newsFeed.entries:
tags = []
for tag in entry['tags']:
tags.append(tag['term'])
blogPosts.append({"title": entry['title'], "link": entry['id'], "published": entry['published'], "tags": tags})
return blogPosts
blogPosts = []
getMediumInfo(blogPosts)
print(blogPosts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment