Stack Overflow notifier
The app notifies about new questions from Stack Overflow. It does that querying the Stack Overflow API: fetch a new question every minute and send a notification about new questions only.
The algorithm
Question IDs are incremental, that makes finding new
questions an easy task.
The notification algorithm uses two vectors and one u32
number containing the latest question ID that is
stored between runs.
It is meant to be running in a loop and execute the following steps:
- Get latest 10 questions of a particular tag
- Save them into an vector of a freshly retrieved records
- Copy new records (those IDs are greater than the latest
question ID) into another vector of new questions
- if the latest question id equals to its initial value of
u32::MAX
(means it's the first run), no new questions would be collected
- if the latest question id equals to its initial value of
- Go through the new questions and send notifications
- Update the value of the latest question ID
- Wait one minute before continuing the loop
Build
Make sure libssl-dev
is installed
# for Ubuntu
sudo apt install libssl-dev
Run it from source with Rust installed
cargo run -- stackoverflow_question_tag
You have to specify a question tag for the questions you are
interested in. For example, the tag can be rust
.
See also the next section to run the app with an API key
Install and run
Being in the project's directory, run
cargo install --path .
By default, the binary goes to .cargo/bin/so_notifier
in your
home directory.
Run it as any other binary with the following command
~/.cargo/bin/so_notifier stackoverflow_question_tag
Also, don't forget to export the auth key if you want a decent API request limit (see The API and throttle).
# ~/.profile
export SO_NOTIFY_AUTH_KEY='<the key>'
Logging
The installed version uses syslog
for logging. By default, the
messages are going to /var/log/syslog
. You can extract the
messages using grep
.
For example
grep so_notifier /var/log/syslog | tail
Logging to a separate file
On Linux:
- Add the following line to
/etc/rsyslog.conf
:
local1.info /var/log/so_notifier.log
- Restart the service
sudo service rsyslog restart
Autostart
An autostart has to be done after the window system starts, so use your window manager autostart facilities. Some sample instructions:
Since the binary is placed in a hidden
directory, you may need
to copy the path from Install and run section.
For Gnome
, go to the applications list, search for
Startup Applications Preferences
. Create a new startup entry and use
an absolute path (this is important).
The API and throttle
The Stackexchange API applies number of throttles, so to use this app in full, follow these instructions:
- Do not execute the same API query more often than once a minute. This app has one minute timeout hardcoded for now. You can increase it, but do not decrease.
- By default, quota number is only 300 requests. That is enough to try, but
not enough if you want the app to run for some significant time.
To increase quota, you would need a Stackexchange application key.
To obtain the key,
register your application.
You can set
OAuth Domain
tolocalhost
, andClient Side OAuth Flow
is not needed. Once it's registered, getKey
from the page with the application credentials.
You can find all registered applications on Your Apps page.