cs2tracker 2.1.4__tar.gz → 2.1.6__tar.gz

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 cs2tracker might be problematic. Click here for more details.

Files changed (34) hide show
  1. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/.gitignore +2 -1
  2. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/.pylintrc +0 -1
  3. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/PKG-INFO +17 -11
  4. cs2tracker-2.1.6/README.md +53 -0
  5. cs2tracker-2.1.6/assets/icons8-counter-strike-bubbles-96.png +0 -0
  6. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker/_version.py +2 -2
  7. cs2tracker-2.1.6/cs2tracker/application.py +207 -0
  8. cs2tracker-2.1.6/cs2tracker/constants.py +553 -0
  9. cs2tracker-2.1.6/cs2tracker/data/config.ini +198 -0
  10. cs2tracker-2.1.6/cs2tracker/data/output.csv +0 -0
  11. cs2tracker-2.1.6/cs2tracker/main.py +34 -0
  12. cs2tracker-2.1.6/cs2tracker/padded_console.py +22 -0
  13. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker/scraper.py +51 -32
  14. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker.egg-info/PKG-INFO +17 -11
  15. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker.egg-info/SOURCES.txt +4 -1
  16. cs2tracker-2.1.4/README.md +0 -47
  17. cs2tracker-2.1.4/cs2tracker/application.py +0 -109
  18. cs2tracker-2.1.4/cs2tracker/constants.py +0 -273
  19. cs2tracker-2.1.4/cs2tracker/data/config.ini +0 -113
  20. cs2tracker-2.1.4/cs2tracker/main.py +0 -43
  21. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/.flake8 +0 -0
  22. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/.isort.cfg +0 -0
  23. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/.pre-commit-config.yaml +0 -0
  24. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/LICENSE.md +0 -0
  25. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/MANIFEST.in +0 -0
  26. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker/__init__.py +0 -0
  27. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker/__main__.py +0 -0
  28. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker.egg-info/dependency_links.txt +0 -0
  29. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker.egg-info/entry_points.txt +0 -0
  30. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker.egg-info/requires.txt +0 -0
  31. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/cs2tracker.egg-info/top_level.txt +0 -0
  32. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/pyproject.toml +0 -0
  33. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/requirements.txt +0 -0
  34. {cs2tracker-2.1.4 → cs2tracker-2.1.6}/setup.cfg +0 -0
@@ -1,9 +1,10 @@
1
- output.csv
2
1
  .vscode
3
2
  __pycache__
4
3
  venv
5
4
  build
5
+ output
6
6
  dist
7
7
  venv-test
8
8
  cs2tracker.egg-info
9
9
  _version.py
10
+ cs2tracker_scraper.bat
@@ -4,7 +4,6 @@ disable=
4
4
  line-too-long,
5
5
  missing-module-docstring,
6
6
  missing-class-docstring,
7
- too-few-public-methods,
8
7
  consider-using-with,
9
8
  import-error,
10
9
  no-else-return
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cs2tracker
3
- Version: 2.1.4
3
+ Version: 2.1.6
4
4
  Summary: Tracking the steam market prices of CS2 items
5
5
  Home-page: https://github.com/ashiven/cs2tracker
6
6
  Author: Jannik Novak
@@ -40,29 +40,35 @@ Dynamic: license-file
40
40
 
41
41
  ### Prerequisites
42
42
 
43
- - Download and install the latest versions of [Python](https://www.python.org/downloads/) and [Pip](https://pypi.org/project/pip/).
44
- - Register for the [Crawlbase Smart Proxy API](https://crawlbase.com/) and retrieve your API key. (Optional)
43
+ - Download and install the latest versions of [Python](https://www.python.org/downloads/) and [Pip](https://pypi.org/project/pip/). (Required for Linux)
44
+ - Register for the [Crawlbase Smart Proxy API](https://crawlbase.com/) and retrieve your API key. (Optional)
45
45
 
46
46
  ### Setup
47
47
 
48
- 1. Install the program via pip:
48
+ #### Windows Executable *(no color support)*
49
+
50
+ - Simply [download the latest executable](https://github.com/ashiven/cs2tracker/releases/latest/download/cs2tracker-windows.zip) and run it.
51
+
52
+ #### Install via Pip
53
+
54
+ 1. Install the program:
49
55
 
50
56
  ```bash
51
- pip install --user cs2tracker
57
+ pip install cs2tracker
52
58
  ```
53
59
 
54
- 2. Start the program:
60
+ 2. Run it:
55
61
  ```bash
56
62
  cs2tracker
57
63
  ```
58
64
 
59
65
  ### Options
60
66
 
61
- - `Run!` to gather the current market prices of your items and calculate the total amount in USD and EUR.
62
- - `Edit Config` to change the specific numbers of each item you own and then save the config file.
63
- - `Show History` to see a price chart consisting of past calculations. A new data point is generated once a day upon running the program.
64
- - `Daily Background Calculation` to automatically run a daily calculation of your investment in the background and save the results such that they can later be viewed via `Show History`.
65
- - If you want to prevent your requests from being rate limited by the steamcommunity server, register for an API key on [Crawlbase](crawlbase.com) and enter it into the `API_Key` field at the end of the config file. This will route every request through a different proxy server.
67
+ - `Run!` to gather the current market prices of your items and calculate the total amount in USD and EUR.
68
+ - `Edit Config` to change the specific numbers of each item you own and then save the config file.
69
+ - `Show History` to see a price chart consisting of past calculations. A new data point is generated once a day upon running the program.
70
+ - `Daily Background Calculation` to automatically run a daily calculation of your investment in the background and save the results such that they can later be viewed via `Show History`.
71
+ - If you want to prevent your requests from being rate limited by the steamcommunity server, register for an API key on [Crawlbase](crawlbase.com) and enter it into the `API_Key` field in the config file. This will route every request through a different proxy server.
66
72
 
67
73
  ---
68
74
 
@@ -0,0 +1,53 @@
1
+ <div align="center">
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4
+ [![GitHub Release](https://img.shields.io/github/v/release/ashiven/cs2tracker)](https://github.com/ashiven/cs2tracker/releases)
5
+ [![PyPI version](https://badge.fury.io/py/cs2tracker.svg)](https://badge.fury.io/py/cs2tracker)
6
+ [![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/ashiven/cs2tracker)](https://github.com/ashiven/cs2tracker/issues)
7
+ [![GitHub Issues or Pull Requests](https://img.shields.io/github/issues-pr/ashiven/cs2tracker)](https://github.com/ashiven/cs2tracker/pulls)
8
+ ![GitHub Repo stars](https://img.shields.io/github/stars/ashiven/cs2tracker)
9
+
10
+ </div>
11
+
12
+ ## About
13
+
14
+ **CS2Tracker** is a tool that can be used to keep track of the steam market prices of your CS2 investment.
15
+
16
+ ## Getting Started
17
+
18
+ ### Prerequisites
19
+
20
+ - Download and install the latest versions of [Python](https://www.python.org/downloads/) and [Pip](https://pypi.org/project/pip/). (Required for Linux)
21
+ - Register for the [Crawlbase Smart Proxy API](https://crawlbase.com/) and retrieve your API key. (Optional)
22
+
23
+ ### Setup
24
+
25
+ #### Windows Executable *(no color support)*
26
+
27
+ - Simply [download the latest executable](https://github.com/ashiven/cs2tracker/releases/latest/download/cs2tracker-windows.zip) and run it.
28
+
29
+ #### Install via Pip
30
+
31
+ 1. Install the program:
32
+
33
+ ```bash
34
+ pip install cs2tracker
35
+ ```
36
+
37
+ 2. Run it:
38
+ ```bash
39
+ cs2tracker
40
+ ```
41
+
42
+ ### Options
43
+
44
+ - `Run!` to gather the current market prices of your items and calculate the total amount in USD and EUR.
45
+ - `Edit Config` to change the specific numbers of each item you own and then save the config file.
46
+ - `Show History` to see a price chart consisting of past calculations. A new data point is generated once a day upon running the program.
47
+ - `Daily Background Calculation` to automatically run a daily calculation of your investment in the background and save the results such that they can later be viewed via `Show History`.
48
+ - If you want to prevent your requests from being rate limited by the steamcommunity server, register for an API key on [Crawlbase](crawlbase.com) and enter it into the `API_Key` field in the config file. This will route every request through a different proxy server.
49
+
50
+ ---
51
+
52
+ > GitHub [@ashiven](https://github.com/Ashiven) &nbsp;&middot;&nbsp;
53
+ > Twitter [ashiven\_](https://twitter.com/ashiven_)
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '2.1.4'
21
- __version_tuple__ = version_tuple = (2, 1, 4)
20
+ __version__ = version = '2.1.6'
21
+ __version_tuple__ = version_tuple = (2, 1, 6)
@@ -0,0 +1,207 @@
1
+ import tkinter as tk
2
+ from subprocess import Popen
3
+ from threading import Thread
4
+ from typing import cast
5
+
6
+ import matplotlib.pyplot as plt
7
+ from matplotlib.axes import Axes
8
+ from matplotlib.dates import DateFormatter
9
+
10
+ from cs2tracker.constants import (
11
+ CONFIG_FILE,
12
+ OS,
13
+ OUTPUT_FILE,
14
+ PYTHON_EXECUTABLE,
15
+ RUNNING_IN_EXE,
16
+ TEXT_EDITOR,
17
+ OSType,
18
+ )
19
+ from cs2tracker.scraper import Scraper
20
+
21
+ WINDOW_TITLE = "CS2Tracker"
22
+ WINDOW_SIZE = "450x380"
23
+ BACKGROUND_COLOR = "#1e1e1e"
24
+ BUTTON_COLOR = "#3c3f41"
25
+ BUTTON_HOVER_COLOR = "#505354"
26
+ BUTTON_ACTIVE_COLOR = "#5c5f61"
27
+ FONT_STYLE = "Segoe UI"
28
+ FONT_COLOR = "white"
29
+
30
+ SCRAPER_WINDOW_TITLE = "CS2Tracker"
31
+ SCRAPER_WINDOW_HEIGHT = 40
32
+ SCRAPER_WINDOW_WIDTH = 100
33
+ SCRAPER_WINDOW_BACKGROUND_COLOR = "Black"
34
+
35
+
36
+ class Application:
37
+ def __init__(self):
38
+ self.scraper = Scraper()
39
+
40
+ def run(self):
41
+ """Run the main application window with buttons for scraping prices, editing the
42
+ configuration, showing history in a chart, and editing the log file.
43
+ """
44
+ application_window = self._configure_window()
45
+ application_window.mainloop()
46
+
47
+ def _add_button(self, frame, text, command):
48
+ """Create and style a button for the main application window."""
49
+ button_style = {
50
+ "font": (FONT_STYLE, 12),
51
+ "fg": FONT_COLOR,
52
+ "bg": BUTTON_COLOR,
53
+ "activebackground": BUTTON_ACTIVE_COLOR,
54
+ }
55
+ button = tk.Button(frame, text=text, command=command, **button_style)
56
+ button.pack(pady=5, fill="x")
57
+ button.bind("<Enter>", lambda _: button.config(bg=BUTTON_HOVER_COLOR))
58
+ button.bind("<Leave>", lambda _: button.config(bg=BUTTON_COLOR))
59
+ return button
60
+
61
+ def _configure_window(self):
62
+ """Configure the main application window UI and add buttons for the main
63
+ functionalities.
64
+ """
65
+ window = tk.Tk()
66
+ window.title(WINDOW_TITLE)
67
+ window.geometry(WINDOW_SIZE)
68
+ window.configure(bg=BACKGROUND_COLOR)
69
+
70
+ frame = tk.Frame(window, bg=BACKGROUND_COLOR, padx=30, pady=30)
71
+ frame.pack(expand=True, fill="both")
72
+
73
+ label = tk.Label(
74
+ frame,
75
+ text=f"Welcome to {WINDOW_TITLE}!",
76
+ font=(FONT_STYLE, 16, "bold"),
77
+ fg=FONT_COLOR,
78
+ bg=BACKGROUND_COLOR,
79
+ )
80
+ label.pack(pady=(0, 30))
81
+
82
+ self._add_button(frame, "Run!", self.scrape_prices)
83
+ self._add_button(frame, "Edit Config", self._edit_config)
84
+ self._add_button(frame, "Show History (Chart)", self._draw_plot)
85
+ self._add_button(frame, "Show History (File)", self._edit_log_file)
86
+
87
+ background_checkbox_value = tk.BooleanVar(value=self.scraper.identify_background_task())
88
+ background_checkbox = tk.Checkbutton(
89
+ frame,
90
+ text="Daily Background Calculation",
91
+ variable=background_checkbox_value,
92
+ command=lambda: self._toggle_background_task(background_checkbox_value.get()),
93
+ bg=BACKGROUND_COLOR,
94
+ fg=FONT_COLOR,
95
+ selectcolor=BUTTON_COLOR,
96
+ activebackground=BACKGROUND_COLOR,
97
+ font=(FONT_STYLE, 10),
98
+ )
99
+ background_checkbox.pack(pady=20)
100
+
101
+ return window
102
+
103
+ def _construct_scraper_command_windows(self):
104
+ """Construct the command to run the scraper in a new window for Windows."""
105
+ set_utf8_encoding = (
106
+ "[Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8;"
107
+ )
108
+ get_size = "$size = $Host.UI.RawUI.WindowSize;"
109
+ set_size = "$Host.UI.RawUI.WindowSize = $size;"
110
+ set_window_title = f"$Host.UI.RawUI.WindowTitle = '{SCRAPER_WINDOW_TITLE}';"
111
+ set_window_width = (
112
+ f"$size.Width = [Math]::Min({SCRAPER_WINDOW_WIDTH}, $Host.UI.RawUI.BufferSize.Width);"
113
+ )
114
+ set_window_height = f"$size.Height = {SCRAPER_WINDOW_HEIGHT};"
115
+ set_background_color = (
116
+ f"$Host.UI.RawUI.BackgroundColor = '{SCRAPER_WINDOW_BACKGROUND_COLOR}';"
117
+ )
118
+ clear = "Clear-Host;"
119
+
120
+ if RUNNING_IN_EXE:
121
+ # The python executable is set as the executable itself in PyInstaller
122
+ scraper_cmd = f"{PYTHON_EXECUTABLE} --only-scrape | Out-Host -Paging"
123
+ else:
124
+ scraper_cmd = f"{PYTHON_EXECUTABLE} -m cs2tracker --only-scrape"
125
+
126
+ cmd = (
127
+ 'start powershell -NoExit -Command "& {'
128
+ + set_utf8_encoding
129
+ + set_window_title
130
+ + get_size
131
+ + set_window_width
132
+ + set_window_height
133
+ + set_size
134
+ + set_background_color
135
+ + clear
136
+ + scraper_cmd
137
+ + '}"'
138
+ )
139
+ return cmd
140
+
141
+ def _construct_scraper_command(self):
142
+ """Construct the command to run the scraper in a new window."""
143
+ if OS == OSType.WINDOWS:
144
+ return self._construct_scraper_command_windows()
145
+ else:
146
+ # TODO: Implement for Linux
147
+ return ""
148
+
149
+ def scrape_prices(self):
150
+ """Scrape prices from the configured sources, print the total, and save the
151
+ results to a file.
152
+ """
153
+ if OS == OSType.WINDOWS:
154
+ scraper_cmd = self._construct_scraper_command()
155
+ Popen(scraper_cmd, shell=True)
156
+ else:
157
+ # TODO: implement external window for Linux
158
+ self.scraper.scrape_prices()
159
+
160
+ def _edit_config(self):
161
+ """Edit the configuration file using the specified text editor."""
162
+ _popen_and_call(
163
+ popen_args={"args": [TEXT_EDITOR, CONFIG_FILE], "shell": True},
164
+ callback=self.scraper.parse_config,
165
+ )
166
+
167
+ def _draw_plot(self):
168
+ """Draw a plot of the scraped prices over time."""
169
+ dates, dollars, euros = self.scraper.read_price_log()
170
+
171
+ fig, ax_raw = plt.subplots(figsize=(10, 8), num="CS2Tracker Price History")
172
+ fig.suptitle("CS2Tracker Price History", fontsize=16)
173
+ fig.autofmt_xdate()
174
+
175
+ ax = cast(Axes, ax_raw)
176
+ ax.plot(dates, dollars, label="Dollars")
177
+ ax.plot(dates, euros, label="Euros")
178
+ ax.legend()
179
+ date_formatter = DateFormatter("%d-%m-%Y")
180
+ ax.xaxis.set_major_formatter(date_formatter)
181
+
182
+ plt.show()
183
+
184
+ def _edit_log_file(self):
185
+ """Opens the file containing past price calculations."""
186
+ Popen([TEXT_EDITOR, OUTPUT_FILE], shell=True)
187
+
188
+ def _toggle_background_task(self, enabled: bool):
189
+ """Toggle whether a daily price calculation should run in the background."""
190
+ self.scraper.toggle_background_task(enabled)
191
+
192
+
193
+ def _popen_and_call(popen_args, callback):
194
+ """
195
+ Runs the given args in a subprocess.Popen, and then calls the function callback when
196
+ the subprocess completes.
197
+
198
+ Source: https://stackoverflow.com/questions/2581817/python-subprocess-callback-when-cmd-exits
199
+ """
200
+
201
+ def process_and_callback(popen_args, callback):
202
+ process = Popen(**popen_args)
203
+ process.wait()
204
+ callback()
205
+
206
+ thread = Thread(target=process_and_callback, args=(popen_args, callback), daemon=True)
207
+ thread.start()