@@ -2,7 +2,12 @@ package twitterv1
22
33import (
44 "fmt"
5+ "net/url"
6+ "strings"
7+ "time"
58
9+ blueskyapi "github.com/Preloading/MastodonTwitterAPI/bluesky"
10+ "github.com/Preloading/MastodonTwitterAPI/bridge"
611 "github.com/gofiber/fiber/v2"
712)
813
@@ -14,50 +19,47 @@ func Search(c *fiber.Ctx) error {
1419}
1520
1621// https://web.archive.org/web/20120313235613/https://dev.twitter.com/docs/api/1/get/trends/%3Awoeid
17- // For now, we will be pretending WOEID doesn't exist
18- // TODO: Implement this with data from bsky
22+ // The bluesky feature to make this possible was released 17 hours ago, and is "beta", so this is likely to break
1923func trends_woeid (c * fiber.Ctx ) error {
20- type Trends struct {
21- Created string `json:"created_at"`
22- Trends []struct {
23- Name string `json:"name"`
24- URL string `json:"url"`
25- Promoted bool `json:"promoted"`
26- Query string `json:"query"`
27- TweetVolume int `json:"tweet_volume"`
28- } `json:"trends"`
29- AsOf string `json:"as_of"`
30- Locations []struct {
31- Name string `json:"name"`
32- WOEID int `json:"woeid"`
33- } `json:"locations"`
24+ // We don't have location specific trends soooooo
25+ // woeid := c.Params("woeid")
26+
27+ //auth
28+ _ , pds , _ , oauthToken , err := GetAuthFromReq (c )
29+ if err != nil {
30+ return c .Status (fiber .StatusUnauthorized ).SendString ("OAuth token not found in Authorization header" )
3431 }
3532
36- return c .JSON (Trends {
37- Created : "2021-09-01T00:00:00Z" ,
38- Trends : []struct {
39- Name string `json:"name"`
40- URL string `json:"url"`
41- Promoted bool `json:"promoted"`
42- Query string `json:"query"`
43- TweetVolume int `json:"tweet_volume"`
44- }{
45- {
46- Name : "Trending Topic" ,
47- URL : "https://twitter.com/search?q=%22Trending%20Topic%22" ,
48- Promoted : false ,
49- Query : "%22Trending%20Topic%22" ,
50- TweetVolume : 10000 ,
51- },
52- },
53- AsOf : "2021-09-01T00:00:00Z" ,
54- Locations : []struct {
55- Name string `json:"name"`
56- WOEID int `json:"woeid"`
57- }{
33+ // Get trends
34+ bsky_trends , err := blueskyapi .GetTrends (* pds , * oauthToken )
35+ if err != nil {
36+ fmt .Println ("Error:" , err )
37+ return c .Status (fiber .StatusInternalServerError ).SendString ("Failed to fetch trends" )
38+ }
39+
40+ trends := []bridge.Trend {}
41+
42+ for _ , trend := range bsky_trends .Topics {
43+ topic_query := url .QueryEscape (trend .Topic )
44+ topic_query = strings .ReplaceAll (topic_query , "%20" , "+" )
45+ trends = append (trends , bridge.Trend {
46+ Name : trend .Topic ,
47+ URL : "https://twitter.com/search?q=" + topic_query ,
48+ Promoted : false ,
49+ Query : topic_query ,
50+ TweetVolume : 1337 , // We can't get this data without search every, single, topic. So we just make it up.
51+ })
52+
53+ }
54+
55+ return c .JSON (bridge.Trends {
56+ Created : time .Now (),
57+ Trends : trends ,
58+ AsOf : time .Now (), // no clue the differ
59+ Locations : []bridge.TrendLocation {
5860 {
5961 Name : "Worldwide" ,
60- WOEID : 1 ,
62+ Woeid : 1 , // Where on earth ID. Since bluesky trends are global, this is always 1
6163 },
6264 },
6365 })
0 commit comments