Documentation
¶
Index ¶
- Constants
- Variables
- func Fetch(url string) ([]byte, error)
- func FetchAndParse(url string) (*html.Node, error)
- func GetAllTags(cb func(t []Tag)) error
- func GetUserHTML(iurl string) ([]byte, error)
- func GetUsersFromID(id int, cb func(u *User)) error
- func QuerySelector(root *html.Node, selector string) (*html.Node, error)
- func QuerySelectorAll(root *html.Node, selector string) ([]*html.Node, error)
- type Article
- type Articles
- type Comment
- type Snapshot
- type Tag
- type User
- type UserPage
Constants ¶
const (
// UserAgent will be used in requests.
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
)
Variables ¶
Functions ¶
func Fetch ¶
Fetch performs a simple GET request to grab html data.
func FetchAndParse ¶
FetchAndParse takes care of the page fetch and root parsing.
func GetAllTags ¶
GetAllTags will fetch all tags returned from the Dev API. An artifical cap of 10,000 pages has been set.
func GetUserHTML ¶
GetUserHTML will fetch a page of tags from the Dev API.
func GetUsersFromID ¶
GetUsersFromID will iterate through all users starting from the ID. An artifical cap has been set to 1m. Dev has roughly 800K users at the moment.
func QuerySelector ¶
QuerySelector will parse a selector and perform a query on the DOM.
Types ¶
type Article ¶
type Article struct { ID int `json:"id"` Type string `json:"type_of"` Title string `json:"title"` Description string `json:"description"` ReadablePublishDate string `json:"readable_publish_date"` Slug string `json:"slug"` Path string `json:"path"` URL string `json:"url"` CommentsCount int `json:"comments_count"` PublicReactionsCount int `json:"public_reactions_count"` CollectionID int `json:"collection_id"` PublishedTimestamp string `json:"published_timestamp"` PositiveReactionsCount int `json:"positive_reactions_count"` CoverImage string `json:"cover_image"` SocialImage string `json:"social_image"` CanonicalURL string `json:"canonical_url"` CreatedAt string `json:"created_at"` EditedAt string `json:"edited_at"` CrosspostedAt string `json:"crossposted_at"` PublishedAt string `json:"published_at"` LastCommentAt string `json:"last_comment_at"` TagList []string `json:"tag_list"` Tags string `json:"tags"` User User `json:"user"` }
Article represents a single user article (post).
func GetAllArticles ¶
GetAllArticles will fetch a all pages of articles for a user from the Dev API. We set an artifical cap at 5 pages (5,000 articles).
func GetArticles ¶
GetArticles will fetch a page of articles for a user from the Dev API.
func ParseArticle ¶
ParseArticle will parse the JSON of a single article.
func ParseArticles ¶
ParseArticles will parse the JSON of a multiple articles.
type Comment ¶
type Comment struct { Title string `json:"title"` URL string `json:"url"` Comment string `json:"comment"` CreatedAt string `json:"created_at"` }
Comment is a user comment.
type Snapshot ¶
type Snapshot struct { User User `json:"user"` Articles Articles `json:"articles"` HTMLPage []byte `json:"html_page"` UserPage UserPage `json:"user_details"` }
Snapshot is an aggregate of all user data. This includes API data as well as data collected over via scraping.
type Tag ¶
type Tag struct { ID int `json:"id"` Name string `json:"name"` BGColorHex string `json:"bg_color_hex"` TextColorHex string `json:"text_color_hex"` }
Tag is an article tag.
func GetTags ¶
GetTags will fetch a page of tags from the Dev API.
type User ¶
type User struct { ID int `json:"id"` Type string `json:"type_of"` Name string `json:"name"` Username string `json:"username"` Summary string `json:"summary"` TwitterUsername string `json:"twitter_username"` GithubUsername string `json:"github_username"` WebsiteURL string `json:"website_url"` Location string `json:"location"` JoinedAt string `json:"joined_at"` ProfileImage string `json:"profile_image"` }
User represents a dev.to user record.
func GetUserByID ¶
GetUserByID will fetch a single user from Dev's API.
func GetUserByUsername ¶
GetUserByUsername will fetch a single user from Dev's API.
func ParseUser ¶
ParseUser will parse the JSON of a single user.
func (*User) JoinedAtTime ¶
JoinedAtTime will return a time struct for the JoinedAt time.
type UserPage ¶
type UserPage struct { Education string `json:"education"` Title string `json:"title"` Company string `json:"company"` CompanyURL string `json:"company_url"` Email string `json:"email"` Links []string `json:"links"` Badges []string `json:"badges"` Comments []Comment `json:"comments"` Skills []string `json:"skills"` Interests []string `json:"interests"` AvailableFor string `json:"available_for"` // TODO: Not Yet Implemented PostCount int `json:"post_count"` CommentCount int `json:"comment_count"` TagsFollowed int `json:"tags_followed"` }
UserPage is a user's web page collected via scraping.
func ParseUserPage ¶
ParseUserPage will parse the HTML of a user's wwww page.