-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made instagram and twitter schema can be the same for almost anything
- Loading branch information
1 parent
45ceecc
commit 8b81773
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from fastapi import FastAPI, Header | ||
from fastapi.responses import RedirectResponse | ||
import re | ||
|
||
|
||
from user_agents import parse | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.get("/instagram/{link}") | ||
async def read_items(link: str ,*, user_agent: str = Header(None)): | ||
|
||
agent = parse(user_agent) | ||
|
||
redi_link = agent.get_os() | ||
|
||
|
||
|
||
|
||
if (agent.is_mobile): | ||
|
||
if (redi_link.find("iOS") == 0): | ||
|
||
return RedirectResponse(url=f"instagram://user?username={link}") | ||
elif (redi_link.find("Android")== 0 ): | ||
return RedirectResponse(url=f"intent://instagram.com/_u/{link}/#Intent;package=com.instagram.android;scheme=https;end") | ||
|
||
else: | ||
return RedirectResponse(url=f"https://instagram.com/{link}") | ||
|
||
|
||
@app.get("/twitter/{link}") | ||
async def read_items(link: str ,*, user_agent: str = Header(None)): | ||
|
||
agent = parse(user_agent) | ||
|
||
redi_link = agent.get_os() | ||
|
||
|
||
|
||
|
||
if (agent.is_mobile): | ||
|
||
if (redi_link.find("iOS") == 0): | ||
|
||
return RedirectResponse(url=f"twitter://user?screen_name={link}") | ||
elif (redi_link.find("Android")== 0 ): | ||
return RedirectResponse(url=f"intent://twitter.com/{link}#Intent;package=com.twitter.android;scheme=https;end") | ||
|
||
else: | ||
return RedirectResponse(url=f"https://twitter.com/{link}") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
user_agents | ||
fastapi |