A simple API to traverse Craigslist endpoints
Project description
Streamline your Craigslist queries with an API that traverses url endpoints. This library goes hand-in-hand with python-craigslist.
Installation
pip install python-craigslist-meta
Examples
Let’s find every car and truck for sale around the world. python-craigslist is required for this example.
from craigslist import CraigslistForSale
from craigslist_meta import Site
for site in Site.all():
if site.has_area():
for area in site:
auto = CraigslistForSale(site=site.key, area=area.key, category='cta')
# fetch posts from auto
else:
auto = CraigslistForSale(site=site.key, category='cta')
# fetch posts from 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 constructor keys for Region, Country, and Site using the keys() class method.
from craigslist_meta import Site
print(Site.keys())
# ['abbotsford', 'aberdeen', 'abilene', ... ]
Similarly, get a list of children keys for Region, Country, and Site instances using the children attribute.
from craigslist_meta import Country
india = Country("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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for python-craigslist-meta-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 546ded0228a7b81b387508a98c236d79ddc87873af12b6bff54dda05895a208a |
|
MD5 | f39bc26851f4189f81af1879f1a18511 |
|
BLAKE2b-256 | 1e677f3a876d1c954d1ad8d8b460612b1e417f742dc873b7641179ba4ff4e9c0 |