ezoic

Monday, July 31, 2017

Amazon python, get number of reviews

import requests

nreviews_re = {'com': re.compile('\d[\d,]+(?= customer review)'), 
               'co.uk':re.compile('\d[\d,]+(?= customer review)'),
               'de': re.compile('\d[\d\.]+(?= Kundenrezens\w\w)')}
no_reviews_re = {'com': re.compile('no customer reviews'), 
                 'co.uk':re.compile('no customer reviews'),
                 'de': re.compile('Noch keine Kundenrezensionen')}

def get_number_of_reviews(asin, country='com'):                                 
    url = 'http://www.amazon.{country}/product-reviews/{asin}'.format(country=country, asin=asin)
    html = requests.get(url).text
    try:
        return int(re.compile('\D').sub('',nreviews_re[country].search(html).group(0)))
    except:
        if no_reviews_re[country].search(html):
            return 0
        else:
            return None  # to distinguish from 0, and handle more cases if necessary


Saturday, July 29, 2017

How to build and use python package.

 e.

distutils is a python standard package. It helps people to package, etc.

For example, we have a directory, and we have three files there, foo.py, bar.py, setup.py

And setup.py has the following content:

from distutils.core import setup
setup(
    name='fooBar',
    version='1.0',
    author='Will',
    author_email='wilber@sh.com',
    url='http://www.cnblogs.com/wilber2013/',
    py_modules=['foo', 'bar'],
)


 We  run python setup.py sdist in that directory. And we will have a package named fooBar-1.0.zip.

And we can unzip the file, and "python setup.py install", and we can use "foo" , "bar" the two packages. 

need to use  "sudo chown -R $USER /usr/local/lib/python2.7"           when run python setup.py install, otherwise permission denied. 


List of python APIs

Here is a list of Python APIs:

http://www.pythonforbeginners.com/api/list-of-python-apis


I mainly focus on two of them:

Amazon Python API.

https://github.com/boto/boto

In fact it is boto package.

Here is a doc on Boto package, how to use it.

https://media.readthedocs.org/pdf/boto/latest/boto.pdf

Here is a video on boto:

https://www.youtube.com/watch?v=arhgSrqy1mM

The Linkedin API is

https://github.com/ozgur/python-linkedin

It is some package created from some user, and can complete some detailed application.










Wednesday, July 26, 2017

How to create a python package.

How to create a python package.

http://pythoncentral.io/how-to-create-a-python-package/


How to package python code

How to package python code

https://python-packaging.readthedocs.io/en/latest/


python console application example

python console application example:

https://stackoverflow.com/questions/9340391/python-interactive-shell-type-application


import readline
import shlex

print('Enter a command to do something, e.g. `create name price`.')
print('To get help, enter `help`.')

while True:
    cmd, *args = shlex.split(input('> '))

    if cmd=='exit':
        break

    elif cmd=='help':
        print('...')

    elif cmd=='create':
        name, cost = args
        cost = int(cost)
        # ...
        print('Created "{}", cost ${}'.format(name, cost))

    # ...

    else:
        print('Unknown command: {}'.format(cmd))




Python imdb, python rotten tomatoes

python imdb:

https://stackoverflow.com/questions/36513597/how-do-you-request-on-imdb-api-in-python


movies = {}
import json, requests
baseurl = "http://omdbapi.com/?t=" #only submitting the title parameter
with open("movies.txt", "r") as fin:
     for line in fin:
         movieTitle = line.rstrip("\n") # get rid of newline characters
         response = requests.get(url + movieTitle)
         if response.status_code == 200:
              movies[movieTitle] = json.loads(response.text)
         else:
              raise ValueError("Bad request!")
print movies['scream']

import json, requests
url = "http://www.omdbapi.com/?t=scream"
response = requests.get(url)
python_dictionary_values = json.loads(response.text)

python rotten tomatoes:

https://www.blog.pythonlibrary.org/2013/11/06/python-101-how-to-grab-data-from-rottentomatoes/

https://pypi.python.org/pypi/rtsimple








code gist

code gist:

http://codegist.net/


python yaml parser

python yaml parser:

https://stackoverflow.com/questions/1773805/how-can-i-parse-a-yaml-file-in-python


Awesome Python

plenty of python  scripts:

https://awesome-python.com/


Python amazon product api



http://codegist.net/code/python-amazon-product-api-pagination/


looking for a man

 I am a mid aged woman.  I was born in 1980. I do not have any kid. no complicated  dating before . I am looking for a man here for marriage...