Alessio 24129c4852 REFACTOR: reduce technical debt, particularly that caused by singleton pattern in pkg/scraper
- ensure all scraper functions have a `api.XYZ` version and a package-level convenience function
	- isolate `the_api` to top-level convenience functions, in preparation for removal
- move a bunch of scraper functions around to be nearby their related functions
- new ErrLoginRequired
- remove obsolete APIv1 stuff (Feed, TweetDetail)
- rename scraper function GetUserFeedGraphqlFor => GetUserFeed
- fix go.mod Go version incorrectly claiming it's compatible with Go 1.16 (should be Go 1.17)
2024-08-09 19:48:50 -07:00

51 lines
1.1 KiB
Go

package scraper
import (
"fmt"
)
type SpaceID string
type Space struct {
ID SpaceID `db:"id"`
ShortUrl string `db:"short_url"`
State string `db:"state"`
Title string `db:"title"`
CreatedAt Timestamp `db:"created_at"`
StartedAt Timestamp
EndedAt Timestamp `db:"ended_at"`
UpdatedAt Timestamp
IsAvailableForReplay bool
ReplayWatchCount int
LiveListenersCount int
ParticipantIds []UserID
CreatedById UserID
TweetID TweetID
IsDetailsFetched bool
}
func (space Space) FormatDuration() string {
duration := space.EndedAt.Time.Sub(space.StartedAt.Time)
h := int(duration.Hours())
m := int(duration.Minutes()) % 60
s := int(duration.Seconds()) % 60
if h != 0 {
return fmt.Sprintf("%dh%02dm", h, m)
}
return fmt.Sprintf("%dm%02ds", m, s)
}
func ParseAPISpace(apiCard APICard) Space {
ret := Space{}
ret.ID = SpaceID(apiCard.BindingValues.ID.StringValue)
ret.ShortUrl = apiCard.ShortenedUrl
// Indicate that this Space needs its details fetched still
ret.IsDetailsFetched = false
return ret
}