X Trending Topics and hashtags APIAPI FEATURES:✅Get top Topics country-wise
✅Get Top Hashtags
Endpoints:/get_trending/
Deploy on
vercel.com for free
from flask import Flask, jsonify
import asyncio
from aiohttp import ClientSession
from bs4 import BeautifulSoup
import random
app = Flask(__name__)
def get_ua():
user_agents = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.3",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.28",
]
return random.choice(user_agents)
@app.route('/get_trending/')
def get_trending(country):
async def fetch_trending(country):
base_url = "https://getdaytrends.com"
url = f"{base_url}/{country}"
ua = get_ua()
headers = {"User-Agent": ua}
async with ClientSession() as session:
async with session.get(url, headers=headers) as response:
content = await response.text()
soup = BeautifulSoup(content, 'html.parser')
tables = soup.select("div[class^='inset']")
results = {}
results['now_trending'] = get_result(tables[0], base_url)
results['today_hashtags'] = get_result(tables[1], base_url)
results['top_hashtags'] = get_result(tables[2], base_url)
return results
def get_result(data, base_url):
tags = data.find_all('tr')
results = []
for tr in tags:
src = tr.td
title = src.get_text()
link = base_url + src.a.get('href')
results.append({'title': title, 'url': link})
return results
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
trending_data = loop.run_until_complete(fetch_trending(country))
return jsonify(trending_data)
if __name__ == '__main__':
app.run(debug=True)
@InfinityTechHub @InfinityTechAPIs
Support: @RealOptimusPrimeBot