Skip to main content

A simple API to traverse Craigslist endpoints

Project description

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

The project is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python-craigslist-meta-0.5.1.tar.gz (23.1 kB view details)

Uploaded Source

File details

Details for the file python-craigslist-meta-0.5.1.tar.gz.

File metadata

  • Download URL: python-craigslist-meta-0.5.1.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.8.5

File hashes

Hashes for python-craigslist-meta-0.5.1.tar.gz
Algorithm Hash digest
SHA256 46a32e99c852180b17e35bdadf3ff86fd2497973f9f490759a3e79a8be1eccdc
MD5 6ed6c2c568c3b0397a53368deecdcaad
BLAKE2b-256 e36259fa1c5798e788617c131860e50f301b1618f0d69e57f1f21a164d485915

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page