-
Notifications
You must be signed in to change notification settings - Fork 2
/
harvest.coffee
53 lines (42 loc) · 1.72 KB
/
harvest.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
path = require 'path'
fs = require 'fs'
Twit = require 'twit'
fs = require 'fs'
twitter_options = {
count: 200
}
data = fs.readFileSync path.join(__dirname, 'README.md'), 'utf8'
data.replace /last imported tweet\:\s*(.*)/g, (match, id) ->
twitter_options.since_id = id
console.error 'last tweet id was:', twitter_options.since_id
config = JSON.parse fs.readFileSync path.join process.env.HOME, '.twit-cli'
twit = new Twit config
twit.get 'statuses/mentions_timeline', twitter_options, (err, data, response) ->
for {id, user, text, entities} in data
if text.match(/^contribute\s+@shecodes/i) is null then continue
#console.log id, user.screen_name, text, entities.urls
urls = (x.expanded_url for x in entities.urls)
mentions = (x.screen_name for x in entities.user_mentions)
tags = (x.text for x in entities.hashtags)
# remove tags from text
for t in tags
text = text.replace '#' + t, ''
# remove metnions
for m in mentions
text = text.replace '@' + m, ''
# remove URLs
for {url} in entities.urls
text = text.replace url, ''
text = text.replace /^contribute/, ''
if urls?.length
console.log "#[#{text.trim()}](#{urls[0]})"
if tags?
console.log "- tags: #{tags.join ' '}"
i = 0
for author in mentions
if i++ is 0 then continue # first mention always is @shecodes_
console.log "- author: @#{author}"
console.log "- contributed_by: @#{user.screen_name}"
console.log '- tweet_id: ' + id
console.log ''
console.log 'last imported tweet: ' + data[0].id