sarnesjo-twhere 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION.yml +1 -1
- data/lib/twhere.rb +8 -3
- metadata +1 -1
data/VERSION.yml
CHANGED
data/lib/twhere.rb
CHANGED
@@ -6,8 +6,10 @@ class Twhere
|
|
6
6
|
def initialize(config_file)
|
7
7
|
config = YAML::load(File.open(config_file))
|
8
8
|
@locations_file = config[:twhere][:locations_file]
|
9
|
-
@tweets_file = config[:twhere][:tweets_file]
|
10
9
|
@template_file = config[:twhere][:template_file]
|
10
|
+
@tweets_file = config[:twhere][:tweets_file]
|
11
|
+
@include_replies = config[:twhere][:include_replies]
|
12
|
+
@include_unlocated = config[:twhere][:include_unlocated]
|
11
13
|
@twitter_username = config[:twitter][:username]
|
12
14
|
@twitter_password = config[:twitter][:password]
|
13
15
|
@google_maps_api_key = config[:google_maps][:api_key]
|
@@ -23,7 +25,7 @@ class Twhere
|
|
23
25
|
# load saved tweets (or don't)
|
24
26
|
tweets = []
|
25
27
|
begin
|
26
|
-
tweets = YAML::load(File.open(@tweets_file))
|
28
|
+
tweets = YAML::load(File.open(@tweets_file)) if @tweets_file
|
27
29
|
rescue Errno::ENOENT
|
28
30
|
end
|
29
31
|
|
@@ -35,11 +37,14 @@ class Twhere
|
|
35
37
|
tweets << h unless tweets.include? h
|
36
38
|
end
|
37
39
|
|
40
|
+
tweets.reject! { |t| t[:text] =~ /^@/ } unless @include_replies
|
41
|
+
tweets.reject! { |t| not t[:text] =~ /#[a-z]+/ } unless @include_unlocated
|
42
|
+
|
38
43
|
# sort tweets, oldest first
|
39
44
|
tweets.sort! { |a, b| a[:twitter_id].to_i <=> b[:twitter_id].to_i }
|
40
45
|
|
41
46
|
# save tweets to file
|
42
|
-
File.open(@tweets_file, 'w') { |f| f.puts tweets.to_yaml }
|
47
|
+
File.open(@tweets_file, 'w') { |f| f.puts tweets.to_yaml } if @tweets_file
|
43
48
|
|
44
49
|
# group tweets by location
|
45
50
|
@located_tweets = {}
|