doing-plugin-twitter-import 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/doing-plugin-twitter-import.rb +54 -27
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d88dbc6489815faa760dcf33b790394aad587b777bbebec01c4cd3526bd72df
|
4
|
+
data.tar.gz: 65e157b50060cd67f924069793a82be556822d21612d6e5d82992f8b1c69ccc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00e03f3fb165f7af7043f4b46a1918cf45930ce6c28f1b27f1bef5004aa72a3aeb17ca70f7690b2c13fb52a6bce6b805cde1db37a53f6edc2a10642b81467f70
|
7
|
+
data.tar.gz: fdb09090680c96ccd8fb533600e845d192fc785472f977cf0694164848b8e7e5cd244d669d6c8a3fef3317230b67a8e94a881bdd1f9038d9193f20ac9724fdf6
|
@@ -31,7 +31,7 @@ module Doing
|
|
31
31
|
key = Doing.setting('plugins.twitter.api_key')
|
32
32
|
secret = Doing.setting('plugins.twitter.api_secret')
|
33
33
|
|
34
|
-
raise PluginException, 'Please add API key/secret to config' if key =~ /^xxxxx/
|
34
|
+
raise PluginException, 'Please add Twitter API key/secret to config. Run `doing config refresh` to add placeholders.' if key =~ /^xxxxx/
|
35
35
|
|
36
36
|
user = Doing.setting('plugins.twitter.user')
|
37
37
|
|
@@ -49,7 +49,9 @@ module Doing
|
|
49
49
|
|
50
50
|
@old_items = wwid.content
|
51
51
|
|
52
|
-
new_items = load_timeline(user)
|
52
|
+
new_items = load_timeline(user, wwid, { prefix: prefix, tags: tags, section: options[:section], autotag: options[:autotag] })
|
53
|
+
|
54
|
+
return if new_items.nil?
|
53
55
|
|
54
56
|
total = new_items.count
|
55
57
|
|
@@ -65,24 +67,7 @@ module Doing
|
|
65
67
|
new_items.each do |item|
|
66
68
|
next if duplicate?(item)
|
67
69
|
|
68
|
-
|
69
|
-
tags.each do |tag|
|
70
|
-
if title =~ /\b#{tag}\b/i
|
71
|
-
title.sub!(/\b#{tag}\b/i, "@#{tag}")
|
72
|
-
else
|
73
|
-
title += " @#{tag}"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
title = wwid.autotag(title) if options[:autotag]
|
77
|
-
title.gsub!(/ +/, ' ')
|
78
|
-
title.strip!
|
79
|
-
section = options[:section] || item.section
|
80
|
-
section ||= wwid.config['current_section']
|
81
|
-
|
82
|
-
new_item = Item.new(item.date, title, section)
|
83
|
-
new_item.note = item.note
|
84
|
-
|
85
|
-
imported.push(new_item)
|
70
|
+
imported.push(item)
|
86
71
|
end
|
87
72
|
|
88
73
|
dups = new_items.count - imported.count
|
@@ -108,25 +93,67 @@ module Doing
|
|
108
93
|
false
|
109
94
|
end
|
110
95
|
|
111
|
-
def self.load_timeline(user)
|
112
|
-
|
96
|
+
def self.load_timeline(user, wwid, options)
|
97
|
+
config_dir = File.join(Util.user_home, '.config', 'doing')
|
98
|
+
id_storage = File.join(config_dir, 'last_tweet_id')
|
99
|
+
Doing.logger.log_now(:info, 'Twitter:', "retrieving timeline for #{user}")
|
100
|
+
|
101
|
+
if File.exist?(id_storage)
|
102
|
+
last_id = IO.read(id_storage).strip.to_i
|
103
|
+
else
|
104
|
+
last_id = nil
|
105
|
+
end
|
106
|
+
|
107
|
+
tweet_options = {
|
113
108
|
count: 200,
|
114
109
|
include_rts: true,
|
115
110
|
exclude_replies: true
|
116
|
-
}
|
111
|
+
}
|
112
|
+
tweet_options[:since_id] = last_id if last_id
|
113
|
+
|
114
|
+
tweets = @client.user_timeline(user, tweet_options).map do |t|
|
115
|
+
{ date: t[:created_at], title: t[:text], id: t[:id] }
|
116
|
+
end
|
117
|
+
if !tweets.nil? && tweets.count.positive?
|
118
|
+
Doing.logger.log_now(:info, 'Twitter:', "found #{tweets.count} new tweets")
|
119
|
+
else
|
120
|
+
Doing.logger.log_now(:info, 'Twitter:', 'no new tweets found')
|
121
|
+
return
|
122
|
+
end
|
117
123
|
|
118
124
|
items = []
|
119
125
|
|
120
|
-
tweets.each do |tweet|
|
121
|
-
|
126
|
+
tweets.reverse.each do |tweet|
|
127
|
+
last_id = tweet[:id] if tweet[:id]
|
128
|
+
date = Time.parse(tweet[:date].strftime('%Y-%m-%d %H:%M -0000')).localtime
|
122
129
|
text = tweet[:title].dup
|
123
130
|
text = text.force_encoding('utf-8') if text.respond_to? :force_encoding
|
124
131
|
input = text.split("\n")
|
125
132
|
title = input[0]
|
126
133
|
note = Note.new(input.slice(1, input.count))
|
127
134
|
|
128
|
-
|
129
|
-
|
135
|
+
title = "#{options[:prefix]} #{title} @done"
|
136
|
+
options[:tags].each do |tag|
|
137
|
+
if title =~ /\b#{tag}\b/i
|
138
|
+
title.sub!(/\b#{tag}\b/i, "@#{tag}")
|
139
|
+
else
|
140
|
+
title += " @#{tag}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
title = wwid.autotag(title) if options[:autotag]
|
144
|
+
title.gsub!(/ +/, ' ')
|
145
|
+
title.strip!
|
146
|
+
section = options[:section] || wwid.config['current_section']
|
147
|
+
|
148
|
+
new_item = Item.new(date, title, section)
|
149
|
+
new_item.note = note
|
150
|
+
|
151
|
+
items << new_item if new_item
|
152
|
+
end
|
153
|
+
|
154
|
+
FileUtils.mkdir(config_dir) unless File.exist?(config_dir)
|
155
|
+
File.open(id_storage, 'w+') do |f|
|
156
|
+
f.puts last_id
|
130
157
|
end
|
131
158
|
|
132
159
|
items
|