Skip to content

Instantly share code, notes, and snippets.

@hammertoe
Created February 6, 2020 15:58
Show Gist options
  • Save hammertoe/147a11444a646c7100cb11354db63887 to your computer and use it in GitHub Desktop.
Save hammertoe/147a11444a646c7100cb11354db63887 to your computer and use it in GitHub Desktop.
Script to fetch content from a Coil post
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