Guest User

Untitled

a guest
Dec 1st, 2018
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. #This imports the python classes in order to run the program.
  2. #Each class imports its own libraries to do the necessary work, please look in the class file for further instructions
  3. import twiterwords2
  4. import wordcheck2
  5.  
  6. #This sets up the intial details to have access to the twiter API, you should replace them with your own credentials.
  7.  
  8. # We use the 'locations' parameter of the twiter streaming API do determine the location of a tweet
  9. # Areas are determined by a box which is determined by two points:
  10. # (i) a south-west corner: determined by a lon-lat tuple (NOTE: the order of points is the inverse from google maps)
  11. # (ii) a north-east corner: determined by another lon- lat tuple (NOTE: the order of points is the inverse from google maps)
  12. # The resulting area coding is a list containing the 4 points, e.g. [SW-lon, NE-lat, SW-lon, NE-lat]
  13.  
  14. #Geospatial assumptions:
  15. #London's south-west corner has been set between Felthan and Croydon; lon = -0.32 , lat = 51.4
  16. #London's north-east corner has been set between Enfield and Hornchurch; lon = 0.132, lat = 51.65
  17. londonarea = ["-0.32,51.4,0.132,51.65"] #
  18. #Exeter's south-west corner has been set between Ide and Alpthinton
  19. #Exeter's north-east corner has been set between Stoke Hill and Whipton
  20. exeterarea = ["-3.55,50.70,3.48,50.73"]
  21.  
  22. # Linguistic Assumptions:
  23. # The twiter API gives plenty of information about the user. One of them being the user language.
  24. # London hosts many language communities, when compared to Exeter, for example.
  25. # I found a strong correlation between users whose language parameter is not english and
  26. # the production of tweets in a language different than Enlgish (which should not participate in
  27. # our count of English mispellings.
  28. # Thus, I will store the language parameter that is used to filter the tweets in a variable, which
  29. # is passed to our bag-of-tweets object. This can be changed if needed
  30. languageparam = "en" # This is for the twiter language parameter
  31. # We also use a language dictionary parameter for checking the word spelling (needed for Python Enchant)
  32. dictparam = "en_UK"
  33.  
  34. # Comparison
  35. # We define below a procedure that compares two spelling objects and returns the name of the inner
  36.  
  37.  
  38.  
  39. if __name__ == '__main__':
  40.  
  41. print """Welcome to Twiter Wars!
  42. This program aims to find out whether the population of Exeter or London are better at spelling.
  43. Please enter the number of tweets that you want us to stream.
  44. For testing purposes, you should use a low number (e.g. 5).
  45. """
  46. username = str(raw_input("Please enter your twiter username "))
  47. password = str(raw_input("Please enter your twiter password "))
  48. tweets2stream = int(input("Please provide us the number of tweets to stream using digits: "))
  49.  
  50. print """Thank you, we are now streaming tweets from London.
  51. Loading London Tweets ----------------------"""
  52.  
  53. #This initialises the stream object
  54. londonwords = twiterwords2.getBagOfTweets(username, password, londonarea, tweets2stream, languageparam)
  55. #print londonwords #uncomment this for debugging purposes
  56.  
  57. print """ Thank you, we are now streaming tweets from Exeter. This might take a little longer.
  58. Loading Exeter Tweets ----------------------"""
  59.  
  60. exeterwords = twiterwords2.getBagOfTweets(username, password, exeterarea, tweets2stream, languageparam)
  61. #print exeterwords #uncomment this for debugging purposes
  62.  
  63. print """Thank you, we are now moving to the analysis phase."""
  64.  
  65. #In the analysis phase, we initialise two spelling objects
  66. londonspelling = wordcheck2.Spelling("London", dictparam, londonwords)
  67. exeterspelling = wordcheck2.Spelling("Exeter", dictparam, exeterwords)
  68. # This analyses the words gathered previously
  69. londonspelling.checkWordLists()
  70. exeterspelling.checkWordLists()
  71. print "Analysis results:"
  72.  
  73. londonspelling.compareSpelling(exeterspelling)
  74.  
  75. #the staments below clear authentication details
  76. username = ""
  77. password = ""
Add Comment
Please, Sign In to add comment