Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # REFORMATTED VERSION OF SOURCECODE FOR PROJECT
- # MADE PURELY TO INCREASE READABILITY
- import urllib
- import urllib2
- import webbrowser
- import json
- import time
- import sys
- from bs4 import BeautifulSoup
- newegg_URL = raw_input('Enter the URL of the Newegg item: \n')
- not_product_code = 'http://www.newegg.com/Product/Product.aspx?Item='
- product_code = newegg_URL.replace(not_product_code, '')
- product_info_URL = 'http://www.ows.newegg.com/Products.egg/' + product_code
- soup = BeautifulSoup(urllib.urlopen(newegg_URL))
- name_with_site = soup.title.string
- name = name_with_site.replace('Newegg.com - ', '')
- print '\n' + name
- data = json.load(urllib2.urlopen(product_info_URL))
- price = data[u'FinalPrice']
- print '\n' + price
- print '\n' + newegg_URL
- product_info = name + '\n\n' + price + '\n\n' + newegg_URL
- continue_or_export = raw_input('\n\nAre you done?' +
- 'To quit the program, type 1. ' +
- 'To export to PasteBin, type 2. \n\n')
- if continue_or_export is '1':
- sys.exit()
- elif continue_or_export is '2':
- print 'Note: Exporting to pastebin only works if one is logged in on their default browser. Attempting now.'
- pastebin_vars = {'api_dev_key':'57fe1369d02477a235057557cbeabaa1',
- 'api_option':'paste',
- 'api_paste_code':product_info}
- response = urllib.urlopen('http://pastebin.com/api/api_post.php', urllib.urlencode(pastebin_vars))
- pastebin_url = response.read()
- print pastebin_url
- webbrowser.open_new_tab(pastebin_url)
- else:
- print 'Your input was not understood. Use "1" or "2" only.'
- #product_category = 0 <- coming soon
- time.sleep(30)
- # VARIABLE NAMES + DESCRIPTIONS
- # newegg_URL - the url of the newegg product found in url
- # soup - the beautiful soup html of the newegg product
- # product_code - code of the product
- # product_info_URL - url of the page that holds price and rating
- # usock - urllib's product info url thing
- # data - json interpretation of the page with details on it
- # price - product price
- # name_with_site - product name
- # name - product name, but without the annoying "newegg.com - " part
- # product_category - product category COMING SOON SO HARD TO DO D:
- # todo: make it take more than one in one instance and make it export to SOMETHING
- # (notepad? pastebin? SOMETHING?)
Advertisement
Add Comment
Please, Sign In to add comment