Skip to content

Commit

Permalink
renaming files to make it clearer. creating subdirectory and ignoring it
Browse files Browse the repository at this point in the history
  • Loading branch information
lordblendi committed May 28, 2017
1 parent 8a515b7 commit 083fd51
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# subdirectories used by the downloader
medium_posts_markdown/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
10 changes: 10 additions & 0 deletions downloader/medium.py → downloader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests
import json


def get_latest_post_ids(user, limit):
"""
Get latest {limit} posts from {user} in JSON format.
Expand Down Expand Up @@ -46,3 +47,12 @@ def get_post_ids(text):
if "Post" in parsed_json["payload"]["references"]:
return parsed_json["payload"]["references"]["Post"].keys()
return []

def download_posts_in_html(user, post_ids):
html_posts = []
main_url = "https://medium.com/@{0}/".format(user)
for post_id in post_ids:
url = main_url + post_id
print(url)

return html_posts
14 changes: 11 additions & 3 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
#!/usr/bin/env python3

import downloader.medium as medium
import downloader.main as downloader
import argparse
import os

parser = argparse.ArgumentParser(prog='run.py', description="Script to convert medium posts to markdown files")
parser.add_argument('-u', metavar='USER', help="username", required=True, type=str)
parser.add_argument('-l', metavar='LIMIT', help="Number of posts to retrieve. Integer, and the default is 10 by Medium. Zero will be swapped to one.", type=int)
args = parser.parse_args()

postIDs = medium.get_latest_post_ids(args.u, args.l)
print(postIDs)
# creating subdirectory

medium_post_dir_markdown = "medium_posts_markdown"

if not os.path.exists(medium_post_dir_markdown):
os.makedirs(medium_post_dir_markdown)

post_ids = downloader.get_latest_post_ids(args.u, args.l)
html_posts = downloader.download_posts_in_html(args.u, post_ids)

0 comments on commit 083fd51

Please sign in to comment.