RadicalTruthHF

Arnav's Python Newegg Project

Jul 2nd, 2012
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. # REFORMATTED VERSION OF SOURCECODE FOR PROJECT
  2. # MADE PURELY TO INCREASE READABILITY
  3.  
  4. import urllib
  5. import urllib2
  6. import webbrowser
  7. import json
  8. import time
  9. import sys
  10. from bs4 import BeautifulSoup
  11.  
  12. newegg_URL = raw_input('Enter the URL of the Newegg item: \n')
  13. not_product_code = 'http://www.newegg.com/Product/Product.aspx?Item='
  14. product_code = newegg_URL.replace(not_product_code, '')
  15. product_info_URL = 'http://www.ows.newegg.com/Products.egg/' + product_code
  16.  
  17.  
  18. soup = BeautifulSoup(urllib.urlopen(newegg_URL))
  19. name_with_site = soup.title.string
  20. name = name_with_site.replace('Newegg.com - ', '')
  21. print '\n' + name
  22.  
  23.  
  24. data = json.load(urllib2.urlopen(product_info_URL))
  25. price = data[u'FinalPrice']
  26. print '\n' + price
  27.  
  28. print '\n' + newegg_URL
  29.  
  30. product_info = name + '\n\n' + price + '\n\n' + newegg_URL
  31.  
  32.  
  33. continue_or_export = raw_input('\n\nAre you done?' +
  34.         'To quit the program, type 1. ' +
  35.         'To export to PasteBin, type 2. \n\n')
  36.  
  37. if continue_or_export is '1':
  38.     sys.exit()
  39. elif continue_or_export is '2':
  40.     print 'Note: Exporting to pastebin only works if one is logged in on their default browser. Attempting now.'
  41.     pastebin_vars = {'api_dev_key':'57fe1369d02477a235057557cbeabaa1',
  42.     'api_option':'paste',
  43.     'api_paste_code':product_info}
  44.     response = urllib.urlopen('http://pastebin.com/api/api_post.php', urllib.urlencode(pastebin_vars))
  45.     pastebin_url = response.read()
  46.     print pastebin_url
  47.     webbrowser.open_new_tab(pastebin_url)
  48. else:
  49.     print 'Your input was not understood. Use "1" or "2" only.'
  50.  
  51. #product_category = 0   <- coming soon
  52.  
  53. time.sleep(30)
  54.  
  55. # VARIABLE NAMES + DESCRIPTIONS
  56. # newegg_URL - the url of the newegg product found in url
  57. # soup - the beautiful soup html of the newegg product
  58. # product_code - code of the product
  59. # product_info_URL - url of the page that holds price and rating
  60. # usock - urllib's product info url thing
  61. # data - json interpretation of the page with details on it
  62. # price - product price
  63. # name_with_site - product name
  64. # name - product name, but without the annoying "newegg.com  - " part
  65. # product_category - product category COMING SOON SO HARD TO DO D:
  66.  
  67. # todo: make it take more than one in one instance and make it export to SOMETHING
  68. # (notepad? pastebin? SOMETHING?)
Advertisement
Add Comment
Please, Sign In to add comment