Giter VIP home page Giter VIP logo

dstclient's Introduction

dstclient - API for derstandard.at

API implementation for crawling the news website Der Standard.

Use it with caution. Admins will hate you for it.

Installation

pip install git+https://github.com/basislagerservices/dstclient

Usage

The most convenient way to access API functions is with the DerStandardAPI class. This interface requires a database where results are stored automatically.

Web API

This example shows how the web API is used to download all postings in a live ticker.

from dstclient import DerStandardAPI, utils

async def main():
    engine = await utils.sqlite_engine("/tmp/database.db")
    api = DerStandardAPI(engine)

    async with api.web() as web:
        ticker = await web.get_ticker(1336696633613)
        postings = []
        async for thread in web.get_ticker_threads(ticker):
            async for p in web.get_thread_postings(thread):
                postings.append(p)

The web API without a database interface is available as the WebAPI class.

Database API

SQLAlchemy is used as the ORM for the database. All types returned by the web API are SQLAlchemy types.

The unified API can be used to access the database. DerStandardAPI.db() returns a database session.

This example shows how all users in the database can be retrieved. See the SQLALchemy documentation for more details.

from dstclient import DerStandardAPI, User, utils

async def main():
    engine = await utils.sqlite_engine("/tmp/database.db")
    api = DerStandardAPI(engine)

    async with api.db() as s:
        users = (await s.execute(select(User))).scalars().all()

By default, the returned session is restricted so that the database is not modified. Commits are not allowed and the database is rolled back after the session. Pass the readonly=False flag if this is not desired.

dstclient's People

Contributors

basislagerservices avatar

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.