Skip to content

Commit

Permalink
more error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
NNTin committed Sep 16, 2018
1 parent d6e9ffa commit 0ced2d3
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
from tweepy.api import API
from discord import Webhook, RequestsWebhookAdapter, Embed
from time import gmtime, strftime
from time import sleep
import discord
import random
import json
import datetime
import html
import re
from config import data_json
import urllib3


class StdOutListener(StreamListener):
Expand Down Expand Up @@ -236,4 +238,31 @@ def on_warning(self, notice):
stream = Stream(auth, l)

print('Twitter stream started.')
stream.filter(follow=data_json['twitter_ids'])
while True:
try:
stream.filter(follow=data_json['twitter_ids'])
except urllib3.exceptions.ProtocolError as error:
print('---------Error---------')
print('This is probably caused by "Connection reset by peer." Ignore. Nothing you can do.')
print(error)
print('Sleeping for 10 seconds then continuing.')
sleep(10)
print('Twitter streaming continues.')
print('-----------------------')
except ConnectionResetError as error:
print('---------Error---------')
print('This is probably caused by "Connection reset by peer." Ignore. Nothing you can do.')
print(error)
print('Sleeping for 10 seconds then continuing.')
sleep(10)
print('Twitter streaming continues.')
print('-----------------------')
except Exception as error:
print('---------Error---------')
print('unknown error')
print("You've found an error. Please contact the owner (https://discord.gg/JV5eUB) "
"and send him what follows below:")
print(error)
print(data_json)
print('-----------------------')
break

0 comments on commit 0ced2d3

Please sign in to comment.