__author__ = "t35khan"

from urllib import request
import json
import re
from getmyapi import GetAPI

google_api_key = GetAPI.getapi("google_api_key")


class GetCountry:
    def getcountry(city):
        link = "https://maps.googleapis.com/maps/api/geocode/json?address={0}&key={1}".format(city, google_api_key)
        data_json = request.urlopen(link).read()
        data_json = data_json.decode("utf-8")
        data_json = json.loads(data_json)
        country = []
        if data_json:
            for entry in data_json["results"]:
                country.append(entry["formatted_address"].split(", ")[-1])
            if len(country) > 1:
                country = GetCountry.bestcountry(country)
                return country
            else:
                return country[0]
        else:
            return False

    def bestcountry(country_list):
        country_dict = {}
        for country in country_list:
import time
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
from getmyapi import GetAPI
__author__ = 't35khan'

consumer_key = GetAPI.getapi('consumer_key')
consumer_secret = GetAPI.getapi('consumer_secret')
access_token = GetAPI.getapi('access_token')
access_secret = GetAPI.getapi('access_secret')

class listener(StreamListener):
    def on_data(self, raw_data):
        try:
            with open ("../input/twitDB.txt",'a') as txtfile:
                txtfile.write(raw_data)
            return True
        except BaseException as e:
            print('Failed ondata',str(e))
            time.sleep(10)

    def on_error(self, status_code):
        print(status_code)

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["syria" or "refugee" or "syrian" or "migrant crisis"])