# pyAttention
A library to monitor information sources
![build](https://github.com/dhrone/pyAttention/actions/workflows/test.yml/badge.svg) [![codecov](https://codecov.io/gh/dhrone/pyAttention/branch/master/graph/badge.svg?token=ZCAT8XRG4W)](https://codecov.io/gh/dhrone/pyAttention)
## Key Features
* Retrieves data from TCP servers, socketIO services, RSS feeds, and SQL databases
* Retrieves basic system data from linux-based computers (disk space, IP address, temperatures)
* Provides a queue interface for retrieving received information
* Supports polling and asynchronous monitoring
* Sources can be run individually or monitored together as a collection
* Sources run in their own thread or can share a thread across a collection
## Installation
```shell
# Installation from pypi
pip pyAttention
# or
# Installation from github
$ git clone https://github.com/dhrone/pyAttention
# Install optional dependencies
# Databases
$ pip install sqlalchemy
$ pip install aiosqlite # For sqlite database support
$ pip install asyncpg # For PostgreSQL
$ pip install aiomysql # For mySQL
# RSS Feeds
$ pip install httpx lxml beautifulsoup4
# socketIO services
$ pip install python-socketio[client]==4.6.* aiohttp
# Local system data
$ pip install psutil netifaces
```
## Quickstart
To retrieve data from a RSS feed
```python
from pyAttention.source import rss
# EXAMPLE: Pull 3 day forecast of Manchester, UK from the BBC News RSS feed
url = 'https://weather-broker-cdn.api.bbci.co.uk/en/forecast/rss/3day/2643123'
from pyAttention.source import rss
src = rss(url, frequency=21600) # Query feed every 6 hours
weather = src.get()
```
To retrieve data from a socketIO service
```python
# EXAMPLE: monitor Volumio metadata from its socketIO API (see https://volumio.org)
from pyAttention.source import socketIO
url = 'http://localhost:3000'
src = socketIO(url)
async def callback(data):
await src.put(data)
src.subscribe('pushState', callback)
src.emit('getState') # Command needed to get Volumio to send a pushState message
state = src.get()
```
To retrieve data from a database
```python
# EXAMPLE: pull data from a locally stored sqlite database
# Create test db
import sqlite3
con = sqlite3.connect('songs.db')
cur = con.cursor()
cur.execute('''CREATE TABLE songs (artist text, title text, album text)''')
cur.execute('''INSERT INTO songs VALUES ('Billie Eilish', 'bad guy', 'When We All Fall Asleep, Where Do We Go?')''')
cur.close()
from pyAttention.source import database
uri = 'sqlite+aiosqlite:///./songs.db'
src = database(uri, 'select * from songs')
songs = src.get()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/dhrone/pyAttention",
"name": "pyAttention",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.9",
"maintainer_email": null,
"keywords": "pyAttention, data, database, rss, sql, socketio, websocket, volumio, mpd, light, weight, message, broker",
"author": "dhrone",
"author_email": "dhrone@dhrone.xyz",
"download_url": "https://files.pythonhosted.org/packages/a9/e1/6cf6a0dd5838e44b72234274a24948aaa00fff06a3abc95cb349ab7531b3/pyattention-0.1.3.tar.gz",
"platform": null,
"description": "# pyAttention\nA library to monitor information sources\n\n![build](https://github.com/dhrone/pyAttention/actions/workflows/test.yml/badge.svg) [![codecov](https://codecov.io/gh/dhrone/pyAttention/branch/master/graph/badge.svg?token=ZCAT8XRG4W)](https://codecov.io/gh/dhrone/pyAttention)\n\n## Key Features\n\n* Retrieves data from TCP servers, socketIO services, RSS feeds, and SQL databases\n* Retrieves basic system data from linux-based computers (disk space, IP address, temperatures)\n* Provides a queue interface for retrieving received information\n* Supports polling and asynchronous monitoring\n* Sources can be run individually or monitored together as a collection\n* Sources run in their own thread or can share a thread across a collection\n\n## Installation\n\n```shell\n# Installation from pypi\npip pyAttention\n\n# or\n# Installation from github\n$ git clone https://github.com/dhrone/pyAttention\n\n# Install optional dependencies\n# Databases\n$ pip install sqlalchemy\n$ pip install aiosqlite # For sqlite database support\n$ pip install asyncpg # For PostgreSQL\n$ pip install aiomysql # For mySQL\n\n# RSS Feeds\n$ pip install httpx lxml beautifulsoup4\n\n# socketIO services\n$ pip install python-socketio[client]==4.6.* aiohttp\n\n# Local system data\n$ pip install psutil netifaces\n```\n\n## Quickstart\n\nTo retrieve data from a RSS feed\n\n```python\nfrom pyAttention.source import rss\n\n# EXAMPLE: Pull 3 day forecast of Manchester, UK from the BBC News RSS feed\nurl = 'https://weather-broker-cdn.api.bbci.co.uk/en/forecast/rss/3day/2643123'\nfrom pyAttention.source import rss\nsrc = rss(url, frequency=21600) # Query feed every 6 hours\nweather = src.get()\n```\n\nTo retrieve data from a socketIO service\n\n```python\n# EXAMPLE: monitor Volumio metadata from its socketIO API (see https://volumio.org) \nfrom pyAttention.source import socketIO\nurl = 'http://localhost:3000'\nsrc = socketIO(url)\n\nasync def callback(data):\n await src.put(data)\n\nsrc.subscribe('pushState', callback)\nsrc.emit('getState') # Command needed to get Volumio to send a pushState message\nstate = src.get()\n```\n\nTo retrieve data from a database\n\n```python\n# EXAMPLE: pull data from a locally stored sqlite database\n# Create test db\nimport sqlite3\ncon = sqlite3.connect('songs.db')\ncur = con.cursor()\ncur.execute('''CREATE TABLE songs (artist text, title text, album text)''')\ncur.execute('''INSERT INTO songs VALUES ('Billie Eilish', 'bad guy', 'When We All Fall Asleep, Where Do We Go?')''')\ncur.close()\n\nfrom pyAttention.source import database\nuri = 'sqlite+aiosqlite:///./songs.db'\nsrc = database(uri, 'select * from songs')\nsongs = src.get()\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library to monitor information sources",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/dhrone/pyAttention",
"Repository": "https://github.com/dhrone/pyAttention"
},
"split_keywords": [
"pyattention",
" data",
" database",
" rss",
" sql",
" socketio",
" websocket",
" volumio",
" mpd",
" light",
" weight",
" message",
" broker"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6ddf4a1070314a6b8f05e2e0ec00df8a33a95a5ad0a40f03eb6893d9bfaf0396",
"md5": "f2d8965e8856519321fa5692c937df55",
"sha256": "fd115c08f34e5a7b8a5411a42ed373e1b8d0d06c671b963ef99d8c65a259f3b6"
},
"downloads": -1,
"filename": "pyattention-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f2d8965e8856519321fa5692c937df55",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.9",
"size": 13871,
"upload_time": "2024-05-23T21:22:19",
"upload_time_iso_8601": "2024-05-23T21:22:19.580685Z",
"url": "https://files.pythonhosted.org/packages/6d/df/4a1070314a6b8f05e2e0ec00df8a33a95a5ad0a40f03eb6893d9bfaf0396/pyattention-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a9e16cf6a0dd5838e44b72234274a24948aaa00fff06a3abc95cb349ab7531b3",
"md5": "0b4035e1af47f4bafb8eac6f5d719938",
"sha256": "fd3dcd1149d7386367dca35dc6c12996f5516fa6d230da71bcb9978c54b83af5"
},
"downloads": -1,
"filename": "pyattention-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "0b4035e1af47f4bafb8eac6f5d719938",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.9",
"size": 13418,
"upload_time": "2024-05-23T21:22:21",
"upload_time_iso_8601": "2024-05-23T21:22:21.561921Z",
"url": "https://files.pythonhosted.org/packages/a9/e1/6cf6a0dd5838e44b72234274a24948aaa00fff06a3abc95cb349ab7531b3/pyattention-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-23 21:22:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dhrone",
"github_project": "pyAttention",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pyattention"
}