psn-monitor 1.5rc4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of psn-monitor might be problematic. Click here for more details.

@@ -0,0 +1,389 @@
1
+ Metadata-Version: 2.4
2
+ Name: psn_monitor
3
+ Version: 1.5rc4
4
+ Summary: Tool implementing real-time tracking of Sony PlayStation (PSN) players activities
5
+ Author-email: Michal Szymanski <misiektoja-pypi@rm-rf.ninja>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/misiektoja/psn_monitor
8
+ Project-URL: Source, https://github.com/misiektoja/psn_monitor
9
+ Project-URL: Changelog, https://github.com/misiektoja/psn_monitor/blob/main/RELEASE_NOTES.md
10
+ Keywords: psn,playstation,monitoring,tracking,real-time,osint,psnawp
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Operating System :: MacOS :: MacOS X
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: PSNAWP>=2.0.0
20
+ Requires-Dist: requests>=2.0
21
+ Requires-Dist: python-dateutil>=2.8
22
+ Requires-Dist: pytz>=2020.1
23
+ Requires-Dist: tzlocal>=4.0
24
+ Requires-Dist: python-dotenv>=0.19
25
+ Dynamic: license-file
26
+
27
+ # psn_monitor
28
+
29
+ psn_monitor is a tool for real-time monitoring of Sony PlayStation (PSN) players' activities.
30
+
31
+ <a id="features"></a>
32
+ ## Features
33
+
34
+ - Real-time tracking of PlayStation users' gaming activity (including detection when a user gets online/offline or plays games)
35
+ - Basic statistics for user activity (duration in different states, time spent playing a game, overall time and number of games played in a session etc.)
36
+ - Email notifications for various events (player gets online/offline, starts/finishes/changes a game, errors)
37
+ - Saving all user activities with timestamps to a CSV file
38
+ - Possibility to control the running copy of the script via signals
39
+
40
+ <p align="center">
41
+ <img src="https://raw.githubusercontent.com/misiektoja/psn_monitor/refs/heads/main/assets/psn_monitor.png" alt="psn_monitor_screenshot" width="85%"/>
42
+ </p>
43
+
44
+ <a id="table-of-contents"></a>
45
+ ## Table of Contents
46
+
47
+ 1. [Requirements](#requirements)
48
+ 2. [Installation](#installation)
49
+ * [Install from PyPI](#install-from-pypi)
50
+ * [Manual Installation](#manual-installation)
51
+ 3. [Quick Start](#quick-start)
52
+ 4. [Configuration](#configuration)
53
+ * [Configuration File](#configuration-file)
54
+ * [PSN NPSSO Code](#psn-npsso-code)
55
+ * [User Privacy Settings](#user-privacy-settings)
56
+ * [Time Zone](#time-zone)
57
+ * [SMTP Settings](#smtp-settings)
58
+ * [Storing Secrets](#storing-secrets)
59
+ 5. [Usage](#usage)
60
+ * [Monitoring Mode](#monitoring-mode)
61
+ * [Email Notifications](#email-notifications)
62
+ * [CSV Export](#csv-export)
63
+ * [Check Intervals](#check-intervals)
64
+ * [Signal Controls (macOS/Linux/Unix)](#signal-controls-macoslinuxunix)
65
+ * [Coloring Log Output with GRC](#coloring-log-output-with-grc)
66
+ 6. [Change Log](#change-log)
67
+ 7. [License](#license)
68
+
69
+ <a id="requirements"></a>
70
+ ## Requirements
71
+
72
+ * Python 3.10 or higher
73
+ * Libraries: [PSNAWP](https://github.com/isFakeAccount/psnawp), `requests`, `python-dateutil`, `pytz`, `tzlocal`, `python-dotenv`
74
+
75
+ Tested on:
76
+
77
+ * **macOS**: Ventura, Sonoma, Sequoia
78
+ * **Linux**: Raspberry Pi OS (Bullseye, Bookworm), Ubuntu 24, Rocky Linux 8.x/9.x, Kali Linux 2024/2025
79
+ * **Windows**: 10, 11
80
+
81
+ It should work on other versions of macOS, Linux, Unix and Windows as well.
82
+
83
+ <a id="installation"></a>
84
+ ## Installation
85
+
86
+ <a id="install-from-pypi"></a>
87
+ ### Install from PyPI
88
+
89
+ ```sh
90
+ pip install psn_monitor
91
+ ```
92
+
93
+ <a id="manual-installation"></a>
94
+ ### Manual Installation
95
+
96
+ Download the *[psn_monitor.py](https://raw.githubusercontent.com/misiektoja/psn_monitor/refs/heads/main/psn_monitor.py)* file to the desired location.
97
+
98
+ Install dependencies via pip:
99
+
100
+ ```sh
101
+ pip install PSNAWP requests python-dateutil pytz tzlocal python-dotenv
102
+ ```
103
+
104
+ Alternatively, from the downloaded *[requirements.txt](https://raw.githubusercontent.com/misiektoja/psn_monitor/refs/heads/main/requirements.txt)*:
105
+
106
+ ```sh
107
+ pip install -r requirements.txt
108
+ ```
109
+
110
+ <a id="quick-start"></a>
111
+ ## Quick Start
112
+
113
+ - Grab your [PSN npsso code](#psn-npsso-code) and track the `psn_user_id` gaming activities:
114
+
115
+ ```sh
116
+ psn_monitor <psn_user_id> -n "your_psn_npsso_code"
117
+ ```
118
+
119
+ Or if you installed [manually](#manual-installation):
120
+
121
+ ```sh
122
+ python3 psn_monitor.py <psn_user_id> -n "your_psn_npsso_code"
123
+ ```
124
+
125
+ To get the list of all supported command-line arguments / flags:
126
+
127
+ ```sh
128
+ psn_monitor --help
129
+ ```
130
+
131
+ <a id="configuration"></a>
132
+ ## Configuration
133
+
134
+ <a id="configuration-file"></a>
135
+ ### Configuration File
136
+
137
+ Most settings can be configured via command-line arguments.
138
+
139
+ If you want to have it stored persistently, generate a default config template and save it to a file named `psn_monitor.conf`:
140
+
141
+ ```sh
142
+ psn_monitor --generate-config > psn_monitor.conf
143
+
144
+ ```
145
+
146
+ Edit the `psn_monitor.conf` file and change any desired configuration options (detailed comments are provided for each).
147
+
148
+ <a id="psn-npsso-code"></a>
149
+ ### PSN NPSSO Code
150
+
151
+ Log in to your [My PlayStation](https://my.playstation.com/) account.
152
+
153
+ In another tab, go to: [https://ca.account.sony.com/api/v1/ssocookie](https://ca.account.sony.com/api/v1/ssocookie)
154
+
155
+ Copy the value of `npsso` code.
156
+
157
+ Provide the `PSN_NPSSO` secret using one of the following methods:
158
+ - Pass it at runtime with `-n` / `--npsso-key`
159
+ - Set it as an [environment variable](#storing-secrets) (e.g. `export PSN_NPSSO=...`)
160
+ - Add it to [.env file](#storing-secrets) (`PSN_NPSSO=...`) for persistent use
161
+
162
+ Fallback:
163
+ - Hard-code it in the code or config file
164
+
165
+ Tokens expire after 2 months. The tool alerts on expiration.
166
+
167
+ If you store the `PSN_NPSSO` in a dotenv file you can update its value and send a `SIGHUP` signal to the process to reload the file with the new `npsso` value without restarting the tool. More info in [Storing Secrets](#storing-secrets) and [Signal Controls (macOS/Linux/Unix)](#signal-controls-macoslinuxunix).
168
+
169
+ <a id="user-privacy-settings"></a>
170
+ ### User Privacy Settings
171
+
172
+ In order to monitor PlayStation user activity, proper privacy settings need to be enabled on the monitored user account.
173
+
174
+ The user should go to [PlayStation account management](https://www.playstation.com/acct/management).
175
+
176
+ The value in **Privacy Settings → Personal Info | Messaging → Online Status and Now Playing** should be set set to **Friends only** or **Anyone**.
177
+
178
+ <a id="time-zone"></a>
179
+ ### Time Zone
180
+
181
+ By default, time zone is auto-detected using `tzlocal`. You can set it manually in `psn_monitor.conf`:
182
+
183
+ ```ini
184
+ LOCAL_TIMEZONE='Europe/Warsaw'
185
+ ```
186
+
187
+ You can get the list of all time zones supported by pytz like this:
188
+
189
+ ```sh
190
+ python3 -c "import pytz; print('\n'.join(pytz.all_timezones))"
191
+ ```
192
+
193
+ <a id="smtp-settings"></a>
194
+ ### SMTP Settings
195
+
196
+ If you want to use email notifications functionality, configure SMTP settings in the `psn_monitor.conf` file.
197
+
198
+ Verify your SMTP settings by using `--send-test-email` flag (the tool will try to send a test email notification):
199
+
200
+ ```sh
201
+ psn_monitor --send-test-email
202
+ ```
203
+
204
+ <a id="storing-secrets"></a>
205
+ ### Storing Secrets
206
+
207
+ It is recommended to store secrets like `PSN_NPSSO` or `SMTP_PASSWORD` as either an environment variable or in a dotenv file.
208
+
209
+ Set environment variables using `export` on **Linux/Unix/macOS/WSL** systems:
210
+
211
+ ```sh
212
+ export PSN_NPSSO="your_psn_npsso_code"
213
+ export SMTP_PASSWORD="your_smtp_password"
214
+ ```
215
+
216
+ On **Windows Command Prompt** use `set` instead of `export` and on **Windows PowerShell** use `$env`.
217
+
218
+ Alternatively store them persistently in a dotenv file (recommended):
219
+
220
+ ```ini
221
+ PSN_NPSSO="your_psn_npsso_code"
222
+ SMTP_PASSWORD="your_smtp_password"
223
+ ```
224
+
225
+ By default the tool will auto-search for dotenv file named `.env` in current directory and then upward from it.
226
+
227
+ You can specify a custom file with `DOTENV_FILE` or `--env-file` flag:
228
+
229
+ ```sh
230
+ psn_monitor <psn_user_id> --env-file /path/.env-psn_monitor
231
+ ```
232
+
233
+ You can also disable `.env` auto-search with `DOTENV_FILE = "none"` or `--env-file none`:
234
+
235
+ ```sh
236
+ psn_monitor <psn_user_id> --env-file none
237
+ ```
238
+
239
+ As a fallback, you can also store secrets in the configuration file or source code.
240
+
241
+ <a id="usage"></a>
242
+ ## Usage
243
+
244
+ <a id="monitoring-mode"></a>
245
+ ### Monitoring Mode
246
+
247
+ To monitor specific user activity, just type the PlayStation (PSN) user's id (`psn_user_id` in the example below):
248
+
249
+ ```sh
250
+ psn_monitor <psn_user_id>
251
+ ```
252
+
253
+ If you have not set `PSN_NPSSO` secret, you can use `-n` flag:
254
+
255
+ ```sh
256
+ psn_monitor <psn_user_id> -n "your_psn_npsso_code"
257
+ ```
258
+
259
+ By default, the tool looks for a configuration file named `psn_monitor.conf` in:
260
+ - current directory
261
+ - home directory (`~`)
262
+ - script directory
263
+
264
+ If you generated a configuration file as described in [Configuration](#configuration), but saved it under a different name or in a different directory, you can specify its location using the `--config-file` flag:
265
+
266
+
267
+ ```sh
268
+ psn_monitor <psn_user_id> --config-file /path/psn_monitor_new.conf
269
+ ```
270
+
271
+ The tool runs until interrupted (`Ctrl+C`). Use `tmux` or `screen` for persistence.
272
+
273
+ You can monitor multiple PSN players by running multiple instances of the script.
274
+
275
+ The tool automatically saves its output to `psn_monitor_<psn_user_id>.log` file. It can be changed in the settings via `PSN_LOGFILE` configuration option or disabled completely via `DISABLE_LOGGING` / `-d` flag.
276
+
277
+ The tool also saves the timestamp and last status (after every change) to `psn_<psn_user_id>_last_status.json` file, so the last status is available after the restart of the tool.
278
+
279
+ <a id="email-notifications"></a>
280
+ ### Email Notifications
281
+
282
+ To enable email notifications when a user gets online or offline:
283
+ - set `ACTIVE_INACTIVE_NOTIFICATION` to `True`
284
+ - or use the `-a` flag
285
+
286
+ ```sh
287
+ psn_monitor <psn_user_id> -a
288
+ ```
289
+
290
+ To be informed when a user starts, stops or changes the played game:
291
+ - set `GAME_CHANGE_NOTIFICATION` to `True`
292
+ - or use the `-g` flag
293
+
294
+ ```sh
295
+ psn_monitor <psn_user_id> -g
296
+ ```
297
+
298
+ To disable sending an email on errors (enabled by default):
299
+ - set `ERROR_NOTIFICATION` to `False`
300
+ - or use the `-e` flag
301
+
302
+ ```sh
303
+ psn_monitor <psn_user_id> -e
304
+ ```
305
+
306
+ Make sure you defined your SMTP settings earlier (see [SMTP settings](#smtp-settings)).
307
+
308
+ Example email:
309
+
310
+ <p align="center">
311
+ <img src="https://raw.githubusercontent.com/misiektoja/psn_monitor/refs/heads/main/assets/psn_monitor_email_notifications.png" alt="psn_monitor_email_notifications" width="80%"/>
312
+ </p>
313
+
314
+ <a id="csv-export"></a>
315
+ ### CSV Export
316
+
317
+ If you want to save all reported activities of the PSN user to a CSV file, set `CSV_FILE` or use `-b` flag:
318
+
319
+ ```sh
320
+ psn_monitor <psn_user_id> -b psn_user_id.csv
321
+ ```
322
+
323
+ The file will be automatically created if it does not exist.
324
+
325
+ <a id="check-intervals"></a>
326
+ ### Check Intervals
327
+
328
+ If you want to customize polling intervals, use `-k` and `-c` flags (or corresponding configuration options):
329
+
330
+ ```sh
331
+ psn_monitor <psn_user_id> -k 30 -c 120
332
+ ```
333
+
334
+ * `PSN_ACTIVE_CHECK_INTERVAL`, `-k`: check interval when the user is online (seconds)
335
+ * `PSN_CHECK_INTERVAL`, `-c`: check interval when the user is offline (seconds)
336
+
337
+ <a id="signal-controls-macoslinuxunix"></a>
338
+ ### Signal Controls (macOS/Linux/Unix)
339
+
340
+ The tool has several signal handlers implemented which allow to change behavior of the tool without a need to restart it with new configuration options / flags.
341
+
342
+ List of supported signals:
343
+
344
+ | Signal | Description |
345
+ | ----------- | ----------- |
346
+ | USR1 | Toggle email notifications when user gets online or offline (-a) |
347
+ | USR2 | Toggle email notifications when user starts/stops/changes the game (-g) |
348
+ | TRAP | Increase the check timer for player activity when user is online (by 30 seconds) |
349
+ | ABRT | Decrease check timer for player activity when user is online (by 30 seconds) |
350
+ | HUP | Reload secrets from .env file |
351
+
352
+ Send signals with `kill` or `pkill`, e.g.:
353
+
354
+ ```sh
355
+ pkill -USR1 -f "psn_monitor <psn_user_id>"
356
+ ```
357
+
358
+ As Windows supports limited number of signals, this functionality is available only on Linux/Unix/macOS.
359
+
360
+ <a id="coloring-log-output-with-grc"></a>
361
+ ### Coloring Log Output with GRC
362
+
363
+ You can use [GRC](https://github.com/garabik/grc) to color logs.
364
+
365
+ Add to your GRC config (`~/.grc/grc.conf`):
366
+
367
+ ```
368
+ # monitoring log file
369
+ .*_monitor_.*\.log
370
+ conf.monitor_logs
371
+ ```
372
+
373
+ Now copy the [conf.monitor_logs](https://raw.githubusercontent.com/misiektoja/psn_monitor/refs/heads/main/grc/conf.monitor_logs) to your `~/.grc/` and log files should be nicely colored when using `grc` tool.
374
+
375
+ Example:
376
+
377
+ ```sh
378
+ grc tail -F -n 100 psn_monitor_<psn_user_id>.log
379
+ ```
380
+
381
+ <a id="change-log"></a>
382
+ ## Change Log
383
+
384
+ See [RELEASE_NOTES.md](https://github.com/misiektoja/psn_monitor/blob/main/RELEASE_NOTES.md) for details.
385
+
386
+ <a id="license"></a>
387
+ ## License
388
+
389
+ Licensed under GPLv3. See [LICENSE](https://github.com/misiektoja/psn_monitor/blob/main/LICENSE).
@@ -0,0 +1,7 @@
1
+ psn_monitor.py,sha256=NYhw5BE18nE6GNTvAALt8JYDKZ0YD2-HbPa2VRjQEUQ,55082
2
+ psn_monitor-1.5rc4.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
3
+ psn_monitor-1.5rc4.dist-info/METADATA,sha256=nmpsBvxaYG8AdbwgScoyTHE_NBJiySyHO3Um2Z-8_0I,12578
4
+ psn_monitor-1.5rc4.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
5
+ psn_monitor-1.5rc4.dist-info/entry_points.txt,sha256=2yXV06LBmzhWnvc4bKuEblezaWSHEWKdB2HClGXZlnk,49
6
+ psn_monitor-1.5rc4.dist-info/top_level.txt,sha256=IG37NL5yiB0wgx_MN-L47SDxKdqRXzjIqBpkU7JiISE,12
7
+ psn_monitor-1.5rc4.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ psn_monitor = psn_monitor:main