Giter Club home page Giter Club logo

python-craigslist-meta's Introduction

python-craigslist-meta

PyPI version fury.io PyPI pyversions

Streamline your Craigslist queries with an API that traverses url endpoints. This library serves as an addition to pycraigslist and python-craigslist.

Installation

pip install python-craigslist-meta

Examples

Let's find every car and truck for sale around the world. pycraigslist is required for this example.

import pycraigslist
from craigslist_meta import Site

for site in Site.all():
    if site.has_area():
        for area in site:
            all_autos = pycraigslist.forsale.cta(site=site.key, area=area.key)
            for auto in all_autos.search():
                print(auto)
    else:
        all_autos = pycraigslist.forsale.cta(site=site.key)
        for auto in all_autos.search():
            print(auto)

We could run the same search using python-craigslist.

from craigslist import CraigslistForSale
from craigslist_meta import Site

for site in Site.all():
    if site.has_area():
        for area in site:
            all_autos = CraigslistForSale(site=site.key, area=area.key, category='cta')
            for auto in all_autos.get_results():
                print(auto)
    else:
        all_autos = CraigslistForSale(site=site.key, category='cta')
        for auto in all_autos.get_results():
                print(auto)

Let's get Craigslist urls of areas in the San Francisco Bay Area.

from craigslist_meta import Site

sfbay = Site("sfbay")
for area in sfbay:
    print(area.url)


# https://sfbay.craigslist.org/eby/
# https://sfbay.craigslist.org/nby/
# https://sfbay.craigslist.org/pen/
# https://sfbay.craigslist.org/sby/
# ...

We can also work with countries. Let's get site keys in Germany.

from craigslist_meta import Country

germany = Country("germany")
for site in germany:
    print(site.key)


# berlin
# bremen
# cologne
# dresden
# ...

Let's get titles of sites in Japan.

from craigslist_meta import Country

japan = Country("japan")
for site in japan:
    print(site.title)


# 福岡
# 広島
# 名古屋
# 沖縄
# ...

Finally, we can go a step further and work with regions.

from craigslist_meta import Region

africa = Region("africa")
for country in africa:
    print(country.title)


# Egypt
# Ethiopia
# Ghana
# Kenya
# ...

Get a list of valid keys for Region, Country, and Site by using the keys class attribute.

from craigslist_meta import Site

print(Site.keys)


# ['abbotsford', 'aberdeen', 'abilene', ... ]
Similarly, get a list of children keys for Region, Country, and Site instances by using the children attribute.
The children heirarchy is as follows: Region --> Country --> Site --> Area
from craigslist_meta import Country

india = Country("india")
# print site keys in India
print(india.children)


# ['ahmedabad', 'bangalore', 'bhubaneswar', ... ]

Contribute

Support

If you are having issues or would like to propose a new feature, please use the issues tracker.

License

This project is licensed under the MIT license.

python-craigslist-meta's People

Contributors

irahorecka avatar

Stargazers

 avatar

Watchers

 avatar

python-craigslist-meta's Issues

Error messages at install

Hi Ira,

Wanted to give your addon a spin and I got this at install

`(venv) C:\Users\mgpd\PycharmProjects\molivo>pip install python-craigslist-meta
Collecting python-craigslist-meta
Downloading python-craigslist-meta-0.1.2.tar.gz (25 kB)
ERROR: Command errored out with exit status 1:
command: 'c:\users\mgpd\pycharmprojects\molivo\venv\scripts\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\mgpd\AppData\Local\Temp\pip-install-ben767ri\python-craigslist-meta_9e7670eace6c41739
a311bc05bd71d6d\setup.py'"'"'; file='"'"'C:\Users\mgpd\AppData\Local\Temp\pip-install-ben767ri\python-craigslist-meta_9e7670eace6c41739a311bc05bd71d6d\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=
f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\mgpd\AppData\Local\Temp\pip-pip-egg-info-rg0y796p'
cwd: C:\Users\mgpd\AppData\Local\Temp\pip-install-ben767ri\python-craigslist-meta_9e7670eace6c41739a311bc05bd71d6d
Complete output (7 lines):
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\mgpd\AppData\Local\Temp\pip-install-ben767ri\python-craigslist-meta_9e7670eace6c41739a311bc05bd71d6d\setup.py", line 26, in
long_description=open("README.rst").read(),
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 1965: character maps to
----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/ca/3e/f6f78b63f674bcc1316199a0c09704a18643ba915d5721d9023d69f42643/python-craigslist-meta-0.1.2.tar.gz#sha256=40c18a9a727981fc318df58780df810ad74cb8703a124cb9b2a4738454e78e4f
(from https://pypi.org/simple/python-craigslist-meta/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
Downloading python-craigslist-meta-0.1.1.tar.gz (24 kB)
Building wheels for collected packages: python-craigslist-meta
Building wheel for python-craigslist-meta (setup.py) ... done
Created wheel for python-craigslist-meta: filename=python_craigslist_meta-0.1.1-py3-none-any.whl size=23857 sha256=6d7c153db9e6958479b83192ddad71d383fec929d3767dda0c69973c739c6e00
Stored in directory: c:\users\mgpd\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local\pip\cache\wheels\45\2a\72\1da8aec745d3e3c2ff8511c57da9983dd4255dddde212e6147
Successfully built python-craigslist-meta
Installing collected packages: python-craigslist-meta
Successfully installed python-craigslist-meta-0.1.1

(venv) C:\Users\mgpd\PycharmProjects\molivo>
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.