Skip to content

Instantly share code, notes, and snippets.

@generall
Created January 15, 2017 11:53
Show Gist options
  • Save generall/f5fbdab58ecfc78bb6a3eb2e3b6d1d67 to your computer and use it in GitHub Desktop.
Save generall/f5fbdab58ecfc78bb6a3eb2e3b6d1d67 to your computer and use it in GitHub Desktop.
Twitter-bot
Twitter bot for automated detection and re-twitting influential thematic posts.
===
Assume that thematic = `programming`
##Stage 1
* Prepare examples of programmer's twitter accounts and other ones for representativity
* Create graph of twitter accounts which seems to contain programmers thematic
* Starting from small amount of truly programmer's accounts collect all of it's followers and following accounts
* Add in queue post perspective ones based on
* follower count
* activity
* NLP topic detection (key words)
* calculate **PageRank** for programmer's *Graph*
###User params in database
* `info_extracted`
* time of extraction
* draft rank
* `tweets_extracted`
* last tweet id
* time of extraction
* last tweet time
* draft tweet rank
* `followers_extracted`
* time of extraction
* need update?
### daemons
* info_update deamon
* source queue: users with `info_extracted = false`
* order: any
* API: `client.user`
* Action: remove from this queue, add to `tweet_queue`, set `tweets_extracted_count = 0`
* tweet load daemon
* source queue: users with `info_extracted = true`
* order: `[ - tweets_extracted_count, rating]`
* API: `c.client.user_timeline`
* Action: update `tweets_extracted_count += 1`, update draft tweet rank, update both queues: tweet and followers, add new users to graph from dialog end re-tweets
* followers load daemon
* source queue: users with `followers_extracted = false, info_extracted = true`
* order: `[ rating || draft tweet rating || draft rating]`
* API: `client.followers`, `client.followers_ids`, `client.friends`, `client.followers_ids`
* Action: Add new users to graph
### Graph
* All info about users
* info about relations
* `follow`
* `friend`
* `retweet` (with count)
* `answered` (with count)
###Twitter APIs
```ruby
# get user
client.user("@vasnetsov93")
# get user`s followers
client.followers("@_trean_")
# get user`s tweets
ts = c.client.user_timeline("@vasnetsov93", count: 100)
ts.first.attrs
# check limits
Twitter::REST::Request.new(tweet_loader.client, :get, 'https://api.twitter.com/1.1/application/rate_limit_status.json', resources: "followers").perform
#=> {:rate_limit_context=>{:access_token=>"380767551-Oas6V96LbMdllrbEdVnKoj1ehhskFoYg30wBwSpg"}, :resources=>{:followers=>{:"/followers/ids"=>{:limit=>15, :remaining=>15, :reset=>1483244343}, :"/followers/list"=>{:limit=>15, :remaining=>14, :reset=>1483243574}}}}
```
```ruby
```
## Stage 2
* Watch posts of perspective peoples for last 24hrs.
* If amount of calculated rating is above some threshold, calculated for this account, show this tweet as candidate for reposting. Rating calculation should assume:
* Weighted by *Graph* re-tweet and like sum
* re-tweet dynamic
* Keep collect and watch statistics for selected tweets
> Written with [StackEdit](https://stackedit.io/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment