Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #This imports the python classes in order to run the program.
- #Each class imports its own libraries to do the necessary work, please look in the class file for further instructions
- import twiterwords2
- import wordcheck2
- #This sets up the intial details to have access to the twiter API, you should replace them with your own credentials.
- # We use the 'locations' parameter of the twiter streaming API do determine the location of a tweet
- # Areas are determined by a box which is determined by two points:
- # (i) a south-west corner: determined by a lon-lat tuple (NOTE: the order of points is the inverse from google maps)
- # (ii) a north-east corner: determined by another lon- lat tuple (NOTE: the order of points is the inverse from google maps)
- # The resulting area coding is a list containing the 4 points, e.g. [SW-lon, NE-lat, SW-lon, NE-lat]
- #Geospatial assumptions:
- #London's south-west corner has been set between Felthan and Croydon; lon = -0.32 , lat = 51.4
- #London's north-east corner has been set between Enfield and Hornchurch; lon = 0.132, lat = 51.65
- londonarea = ["-0.32,51.4,0.132,51.65"] #
- #Exeter's south-west corner has been set between Ide and Alpthinton
- #Exeter's north-east corner has been set between Stoke Hill and Whipton
- exeterarea = ["-3.55,50.70,3.48,50.73"]
- # Linguistic Assumptions:
- # The twiter API gives plenty of information about the user. One of them being the user language.
- # London hosts many language communities, when compared to Exeter, for example.
- # I found a strong correlation between users whose language parameter is not english and
- # the production of tweets in a language different than Enlgish (which should not participate in
- # our count of English mispellings.
- # Thus, I will store the language parameter that is used to filter the tweets in a variable, which
- # is passed to our bag-of-tweets object. This can be changed if needed
- languageparam = "en" # This is for the twiter language parameter
- # We also use a language dictionary parameter for checking the word spelling (needed for Python Enchant)
- dictparam = "en_UK"
- # Comparison
- # We define below a procedure that compares two spelling objects and returns the name of the inner
- if __name__ == '__main__':
- print """Welcome to Twiter Wars!
- This program aims to find out whether the population of Exeter or London are better at spelling.
- Please enter the number of tweets that you want us to stream.
- For testing purposes, you should use a low number (e.g. 5).
- """
- username = str(raw_input("Please enter your twiter username "))
- password = str(raw_input("Please enter your twiter password "))
- tweets2stream = int(input("Please provide us the number of tweets to stream using digits: "))
- print """Thank you, we are now streaming tweets from London.
- Loading London Tweets ----------------------"""
- #This initialises the stream object
- londonwords = twiterwords2.getBagOfTweets(username, password, londonarea, tweets2stream, languageparam)
- #print londonwords #uncomment this for debugging purposes
- print """ Thank you, we are now streaming tweets from Exeter. This might take a little longer.
- Loading Exeter Tweets ----------------------"""
- exeterwords = twiterwords2.getBagOfTweets(username, password, exeterarea, tweets2stream, languageparam)
- #print exeterwords #uncomment this for debugging purposes
- print """Thank you, we are now moving to the analysis phase."""
- #In the analysis phase, we initialise two spelling objects
- londonspelling = wordcheck2.Spelling("London", dictparam, londonwords)
- exeterspelling = wordcheck2.Spelling("Exeter", dictparam, exeterwords)
- # This analyses the words gathered previously
- londonspelling.checkWordLists()
- exeterspelling.checkWordLists()
- print "Analysis results:"
- londonspelling.compareSpelling(exeterspelling)
- #the staments below clear authentication details
- username = ""
- password = ""
Add Comment
Please, Sign In to add comment