Created
December 10, 2022 01:50
-
-
Save danromero/0ca1db239e046eff292924a6d8d0cc5d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 requests | |
from flask import Flask, request | |
app = Flask(__name__) | |
@app.route('/casts/<cast_id>') | |
def show_cast(cast_id): | |
# Use the requests library to make a GET request to the external API | |
# with the bearer token in the Authorization header | |
response = requests.get( | |
'https://api.farcaster.xyz/v2/cast?hash={}'.format(cast_id), | |
headers={'Authorization': 'Bearer ...'} | |
) | |
# Parse the JSON data from the response | |
data = response.json() | |
# Use the data to build an HTML page with Tailwind styles | |
html = ''' | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"> | |
</head> | |
<body class="flex justify-center items-center h-screen"> | |
<div class="relative p-4 mb-4 bg-white rounded-lg shadow-lg max-w-lg"> | |
<div class="flex items-center mb-4"> | |
<img src="{profile_photo_url}" alt="Profile photo" class="w-12 h-12 rounded-full mr-4 border-2 border-gray-300"> | |
<div class="text-xl font-bold">{username}</div> | |
</div> | |
<p class="mb-4">{body}</p> | |
<div class="flex justify-between items-center mb-4"> | |
<div class="text-gray-600">{replies_count} Replies</div> | |
<div class="flex"> | |
<button class="px-2 py-1 mr-2 text-gray-600">Like</button> | |
<button class="px-2 py-1 text-gray-600">Retweet</button> | |
</div> | |
</div> | |
</div> | |
</body> | |
</html> | |
'''.format(profile_photo_url=data['result']['cast']['author']['pfp']['url'], | |
username=data['result']['cast']['author']['username'], | |
body=data['result']['cast']['text'], | |
replies_count=data['result']['cast']['replies']['count'], | |
) | |
return html | |
if __name__ == '__main__': | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment