Created
February 6, 2020 15:58
-
-
Save hammertoe/147a11444a646c7100cb11354db63887 to your computer and use it in GitHub Desktop.
Script to fetch content from a Coil post
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 argparse | |
import requests | |
import json | |
from urllib.parse import urlparse | |
parser = argparse.ArgumentParser(description="Fetch content from a coil post") | |
parser.add_argument("url", help="URL to fetch from Coil") | |
args = parser.parse_args() | |
url_parts = urlparse(args.url) | |
path = url_parts[2] | |
path_parts = path.split('/') | |
assert(path_parts[1] == 'p') | |
username = path_parts[2] | |
post_id = path_parts[-1] | |
gq_api_url = "https://coil.com/graphql" | |
query = """query GetPost($author: String, $postId: String, $postPermanentId: String) {""" \ | |
""" getPost(author: $author, postId: $postId, permanentId: $postPermanentId) { content }""" \ | |
"""}""" | |
data = {"operationName":"GetPost", | |
"variables":{"author":username, | |
"postPermanentId":post_id}, | |
"query": query} | |
data = json.dumps(data) | |
headers = {"content-type": "application/json"} | |
req = requests.post(gq_api_url, | |
headers=headers, | |
data=data) | |
res = req.json() | |
content = res['data']['getPost']['content'] | |
print(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment