-
Notifications
You must be signed in to change notification settings - Fork 6
/
getWeatherTweets.py
executable file
·113 lines (102 loc) · 3.1 KB
/
getWeatherTweets.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from dbco import *
##THIS PROGRAM FINDS THE WEATHER DURING A TIME PERIOD BY READING TWEETS!
##_id
##author
##text
##hashtags
##place
##words
##timestamp
##mentions
##guid
##blue
##blizzard
##chilly
##cloud
##cloudy
##freezing
##cold
##cool
##dark
##drizzle
##duststorm
##fog
##gray
##heat
##hot
##hurricane
##ice
##lightening
##moisture
##rain
##rainbow
##sandstorm
##sky
##smog
##smoke
##snow
##storm
##sunset
##sunrise
##thunder
##tornado
##typhoon
##warm
##weather
##wind
##rainy, cloudy, sunny
##cold, warm
##windy
def guessWeather(startTimestamp, endTimestamp):
basicKeywordList = ["weather"]
coldKeywordList = ["chilly", "freezing", "cold"]
warmKeywordList = ["heat", "hot", "warm"]
rainyKeywordList = ["drizzle", "rain", "rains", "rainy", "raining"]
cloudyKeywordList = ["cloud", "clouds", "cloudy"]
sunnyKeywordList = ["sunny", "rainbow"]
windyKeywordList = ["blizzard", "hurricane", "storm", "wind", "windy"]
overallKeywordList = basicKeywordList + coldKeywordList + warmKeywordList + rainyKeywordList + cloudyKeywordList + sunnyKeywordList + windyKeywordList
overallWordList = []
coldCount = 0
warmCount = 0
rainyCount = 0
cloudyCount = 0
sunnyCount = 0
windyCount = 0
tweetPool = list(db.tweet.find({'timestamp' : {'$gte' : startTimestamp, '$lt' : endTimestamp}, 'words' : {'$in' : overallKeywordList}}))
for tweet in tweetPool:
for word in tweet['words']:
if word in overallKeywordList:
overallWordList.append(word)
for word in overallWordList:
if word in coldKeywordList:
coldCount += 1
elif word in warmKeywordList:
warmCount += 1
elif word in rainyKeywordList:
rainyCount += 1
elif word in cloudyKeywordList:
cloudyCount += 1
elif word in sunnyKeywordList:
sunnyCount += 1
elif word in windyKeywordList:
windyCount += 1
coldPercentage = "unavailable"
warmPercentage = "unavailable"
rainyPercentage = "unavailable"
cloudyPercentage = "unavailable"
sunnyPercentage = "unavailable"
if (coldCount + warmCount > 0):
coldPercentage = int(coldCount * 100 / float(coldCount + warmCount))
warmPercentage = int(warmCount * 100 / float(coldCount + warmCount))
if (rainyCount + cloudyCount + windyCount > 0):
rainyPercentage = int(rainyCount * 100 / float(rainyCount + cloudyCount + sunnyCount))
cloudyPercentage = int(cloudyCount * 100 / float(rainyCount + cloudyCount + sunnyCount))
sunnyPercentage = int(sunnyCount * 100 / float(rainyCount + cloudyCount + sunnyCount))
print str(coldPercentage) + "% of people claim it was cold during the time period"
print str(warmPercentage) + "% of people claim it was warm during the time period"
print
print str(rainyPercentage) + "% of people claim it was rainy during the time period"
print str(cloudyPercentage) + "% of people claim it was cloudy during the time period"
print str(sunnyPercentage) + "% of people claim it was sunny during the time period"
guessWeather(1440300000, 1440355000)