Advertisement
Guest User

Wikipedia Random Article Generator

a guest
Aug 25th, 2013
4,668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import urllib2, string, webbrowser, time, sys, thread
  2.  
  3. x = 1
  4.  
  5. while True:
  6.  
  7. #print "Downloading new list."
  8.  
  9. while x == 1:
  10. print """WELCOME TO WIKIPEDIA RANDOM LIST GENERATOR
  11. Press enter to skip article
  12. type in any letter and press enter to view article
  13. """
  14. print "Downloading new list."
  15. random_list = urllib2.urlopen("http://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=10&format=json").read()
  16. print"""Download complete
  17. ************************"""
  18. break
  19.  
  20.  
  21. #def listget():
  22. random_list2 = urllib2.urlopen("http://en.wikipedia.org/w/api.php?action=query&list=random&rnnamespace=0&rnlimit=10&format=json").read()
  23. #return random_list
  24.  
  25. #thread.start_new_thread(listget,(),)
  26.  
  27.  
  28.  
  29. #print"Download complete"
  30.  
  31. #print random_list
  32.  
  33. letters = 10
  34.  
  35. while letters > 0:
  36.  
  37. idstr = '"id":'
  38. end_idstr = ',"ns"'
  39.  
  40. id_location = random_list.find(idstr)
  41. end_id_location = random_list.find(end_idstr)
  42.  
  43.  
  44. spot_of_id = id_location + 5
  45.  
  46. ID_code = random_list[spot_of_id:end_id_location]
  47.  
  48. #print "ID:", random_list[spot_of_id:end_id_location]
  49.  
  50. random_list = random_list[end_id_location:]
  51.  
  52. namestr = '"title":"'
  53.  
  54. end_namestr = '"}'
  55.  
  56. name_location = random_list.find(namestr)
  57. end_name_location = random_list.find(end_namestr)
  58.  
  59.  
  60. spot_of_name = name_location + 9
  61.  
  62. name = random_list[spot_of_name:end_name_location]
  63.  
  64. #print "Name:", random_list[spot_of_name:end_name_location]
  65.  
  66. print """
  67. """
  68.  
  69.  
  70.  
  71. decision = raw_input(name)
  72.  
  73. decision.upper()
  74.  
  75. if decision == "":
  76.  
  77. random_list = random_list[end_name_location:]
  78.  
  79. letters = letters - 1
  80.  
  81. elif decision == "QUIT":
  82.  
  83. sys.exit()
  84.  
  85. else:
  86.  
  87. website = "http://en.wikipedia.org/wiki?curid=" + ID_code
  88. webbrowser.open(website)
  89.  
  90.  
  91. random_list = random_list2
  92. x=10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement