-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from thepanacealab/finaledits
update streaming.py
- Loading branch information
Showing
1 changed file
with
5 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# The streaming.py code is compiled using the code from Global Connectivity and Multilinguals in the Twitter Network | ||
# Paper citation - Hale, S. A. (2014) Global Connectivity and Multilinguals in the Twitter Network.In Proceedings of the 2014 ACM Annual Conference on Human Factors in Computing Systems, ACM (Montreal, Canada). | ||
# Please cite this paper if using streaming.py code | ||
|
||
from tweepy.streaming import StreamListener | ||
from tweepy import OAuthHandler | ||
from tweepy import Stream | ||
|
@@ -9,12 +13,6 @@ | |
import zipfile | ||
import zlib | ||
|
||
try: | ||
import smtplib | ||
from email.mime.text import MIMEText | ||
except: | ||
sys.stderr.write("Error loading smtplib. Will not be able to send emails...\n") | ||
|
||
# Output directory to hold json files (one per day) with tweets | ||
# Within the output directory, the script loads a file named FILTER with the terms to be tracked (one per line) | ||
|
||
|
@@ -76,7 +74,7 @@ def rotateFiles(self): | |
try: | ||
self.fh.close() | ||
except: | ||
#Log/Email it | ||
#Log it | ||
pass | ||
self.filename=filenow | ||
self.fh = open(self.basePath + "/" + self.filename,"a") | ||
|
@@ -150,13 +148,6 @@ class TimeoutException(Exception): | |
try: | ||
info = str(e) | ||
sys.stderr.write("%s - Unexpected exception. %s\n"%(datetime.now(),info)) | ||
msg = MIMEText("Unexpected error in Twitter collector. Check server. %s"%info) | ||
msg['Subject'] = "Unexpected error in Twitter collector" | ||
msg['From'] = "[email protected]" | ||
msg['To'] = email | ||
s = smtplib.SMTP("smtp.example.com") #Update this to your SMTP server | ||
s.sendmail("[email protected]", email, msg.as_string()) | ||
s.quit() | ||
except: | ||
pass | ||
time.sleep(1800)#Sleep thirty minutes and resume | ||
|