appintel 1.0.2__tar.gz → 1.0.3__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.
@@ -0,0 +1,105 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ env/
12
+ build/
13
+ develop-eggs/
14
+ dist/
15
+ downloads/
16
+ eggs/
17
+ .eggs/
18
+ lib/
19
+ lib64/
20
+ parts/
21
+ sdist/
22
+ var/
23
+ wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+
28
+ # PyInstaller
29
+ # Usually these files are written by a python script from a template
30
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ .hypothesis/
48
+
49
+ # Translations
50
+ *.mo
51
+ *.pot
52
+
53
+ # Django stuff:
54
+ *.log
55
+ local_settings.py
56
+
57
+ # Flask stuff:
58
+ instance/
59
+ .webassets-cache
60
+
61
+ # Scrapy stuff:
62
+ .scrapy
63
+
64
+ # Sphinx documentation
65
+ docs/_build/
66
+
67
+ # PyBuilder
68
+ target/
69
+
70
+ # Jupyter Notebook
71
+ .ipynb_checkpoints
72
+
73
+ # pyenv
74
+ .python-version
75
+
76
+ # celery beat schedule file
77
+ celerybeat-schedule
78
+
79
+ # SageMath parsed files
80
+ *.sage.py
81
+
82
+ # dotenv
83
+ .env
84
+
85
+ # virtualenv
86
+ .venv
87
+ venv/
88
+ ENV/
89
+
90
+ # Spyder project settings
91
+ .spyderproject
92
+ .spyproject
93
+
94
+ # Rope project settings
95
+ .ropeproject
96
+
97
+ # mkdocs documentation
98
+ /site
99
+
100
+ # mypy
101
+ .mypy_cache/
102
+
103
+ # outputfiles
104
+ *.json
105
+ /itunizer/*.json
@@ -1,25 +1,33 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.5
2
2
  Name: appintel
3
- Version: 1.0.2
3
+ Version: 1.0.3
4
4
  Summary: A command line tool to search and compare prices of apps and music on the Apple Store
5
- Author: James Campbell
6
- Author-email: james@jamescampbell.us
7
- Requires-Python: >=3.11,<4.0
8
- Classifier: Programming Language :: Python :: 3
5
+ Project-URL: Homepage, https://github.com/james-see/appintel
6
+ Project-URL: Repository, https://github.com/james-see/appintel
7
+ Project-URL: Issues, https://github.com/james-see/appintel/issues
8
+ Author-email: James Campbell <james@jamescampbell.us>
9
+ Maintainer-email: James Campbell <james@jamescampbell.us>
10
+ License-Expression: GPL-3.0-or-later
11
+ License-File: LICENSE
12
+ Keywords: api,apple-store,data-analysis,itunes,market-research,pricing
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
9
19
  Classifier: Programming Language :: Python :: 3.11
10
20
  Classifier: Programming Language :: Python :: 3.12
11
- Requires-Dist: argparse (>=1.4.0,<2.0.0)
12
- Requires-Dist: black (>=24.4.2,<25.0.0)
13
- Requires-Dist: certifi (>=2024.2.2,<2025.0.0)
14
- Requires-Dist: chardet (>=5.2.0,<6.0.0)
15
- Requires-Dist: idna (>=3.7,<4.0)
16
- Requires-Dist: numpy (>=1.26.4,<2.0.0)
17
- Requires-Dist: pandas (>=2.2.2,<3.0.0)
18
- Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
19
- Requires-Dist: pytz (>=2024.1,<2025.0)
20
- Requires-Dist: requests (>=2.31.0,<3.0.0)
21
- Requires-Dist: six (>=1.16.0,<2.0.0)
22
- Requires-Dist: urllib3 (>=2.2.1,<3.0.0)
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Programming Language :: Python :: 3.15
24
+ Classifier: Topic :: Utilities
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: requests>=2.31.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
29
+ Requires-Dist: pytest>=8.0; extra == 'dev'
30
+ Requires-Dist: ruff>=0.6; extra == 'dev'
23
31
  Description-Content-Type: text/markdown
24
32
 
25
33
  # appintel
@@ -68,4 +76,3 @@ It is difficult to get nice structured data from Apple. This helps with that.
68
76
  ## Example search
69
77
 
70
78
  !['example'](https://user-images.githubusercontent.com/616585/35492868-5dcf0e90-047d-11e8-974f-0dd7a0f33311.png)
71
-
@@ -0,0 +1,3 @@
1
+ from .appintel import __version__, main
2
+
3
+ __all__ = ["__version__", "main"]
@@ -0,0 +1,205 @@
1
+ """A command line tool to search and compare prices of apps and music on the Apple Store."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ from pprint import pprint
8
+ from statistics import mean, median
9
+
10
+ import requests
11
+
12
+ __version__ = "1.0.3"
13
+
14
+ logo = """
15
+ +-------------------------------------+
16
+ | --\\ |
17
+ | / -\\ |
18
+ | / -\\ |
19
+ | / - |
20
+ | \\ / |
21
+ | \\ / |
22
+ | \\ -/ |
23
+ | -\\ / |
24
+ | \\ / |
25
+ | \\ / AppIntel |
26
+ | \\ / |
27
+ | -/ |
28
+ +-------------------------------------+
29
+ """
30
+
31
+ ITUNES_URL_ENDPOINT = "https://itunes.apple.com/search?term={}&country={}&entity={}"
32
+
33
+
34
+ def get_content(
35
+ search_term: str, store_country: str = "us", category: str = "software"
36
+ ) -> requests.Response:
37
+ """Fetch data from the iTunes search endpoint."""
38
+ return requests.get(
39
+ ITUNES_URL_ENDPOINT.format(search_term, store_country, category),
40
+ timeout=10,
41
+ )
42
+
43
+
44
+ def _prices(jsondata: dict) -> list[float]:
45
+ return [float(item.get("price")) for item in jsondata.get("results", []) if "price" in item]
46
+
47
+
48
+ def get_mean(jsondata: dict) -> float:
49
+ prices = _prices(jsondata)
50
+ if not prices:
51
+ return 0.0
52
+ if len(prices) > 1:
53
+ return mean(prices)
54
+ return prices[0]
55
+
56
+
57
+ def get_max(jsondata: dict) -> float:
58
+ prices = _prices(jsondata)
59
+ if not prices:
60
+ return 0.0
61
+ if len(prices) > 1:
62
+ return max(prices)
63
+ return prices[0]
64
+
65
+
66
+ def get_min(jsondata: dict) -> float:
67
+ prices = _prices(jsondata)
68
+ if not prices:
69
+ return 0.0
70
+ if len(prices) > 1:
71
+ return min(prices)
72
+ return prices[0]
73
+
74
+
75
+ def get_median(jsondata: dict) -> float:
76
+ prices = _prices(jsondata)
77
+ if not prices:
78
+ return 0.0
79
+ if len(prices) > 1:
80
+ return median(prices)
81
+ return prices[0]
82
+
83
+
84
+ def format_table(results: list[dict]) -> str:
85
+ if not results:
86
+ return "(no results)"
87
+ values = [
88
+ (str(item.get("price")), str(item.get("artistName")), str(item.get("trackName")))
89
+ for item in results
90
+ ]
91
+ header = ("price", "artistName", "trackName")
92
+ rows = [header, *values]
93
+ widths = [max(len(row[index]) for row in rows) for index in range(3)]
94
+ lines = [" | ".join(field.ljust(widths[index]) for index, field in enumerate(header))]
95
+ lines.append("-+-".join("-" * widths[index] for index in range(3)))
96
+ lines.extend(
97
+ " | ".join(field.ljust(widths[index]) for index, field in enumerate(row)) for row in values
98
+ )
99
+ return "\n".join(lines)
100
+
101
+
102
+ def build_parser() -> argparse.ArgumentParser:
103
+ parser = argparse.ArgumentParser(
104
+ description="Collect and summarize data from the Apple iTunes Store",
105
+ formatter_class=argparse.ArgumentDefaultsHelpFormatter,
106
+ )
107
+ parser.add_argument(
108
+ "-s",
109
+ "--search",
110
+ dest="search_term",
111
+ default="nginx",
112
+ help="search term for the iTunes store",
113
+ )
114
+ parser.add_argument(
115
+ "-c",
116
+ "--category",
117
+ dest="category_location",
118
+ default="software",
119
+ help="store category to search",
120
+ )
121
+ parser.add_argument(
122
+ "-p",
123
+ "--print",
124
+ dest="print_me",
125
+ action="store_true",
126
+ default=False,
127
+ help="print raw search results",
128
+ )
129
+ parser.add_argument(
130
+ "-n",
131
+ "--no-logo",
132
+ dest="logo_off",
133
+ action="store_true",
134
+ default=False,
135
+ help="disable the AppIntel logo",
136
+ )
137
+ parser.add_argument(
138
+ "-t",
139
+ "--table",
140
+ dest="output_table",
141
+ action="store_true",
142
+ default=False,
143
+ help="print a compact table instead of JSON",
144
+ )
145
+ parser.add_argument(
146
+ "--country",
147
+ dest="store_country",
148
+ default="us",
149
+ help="store country to search",
150
+ )
151
+ parser.add_argument(
152
+ "--version",
153
+ "-v",
154
+ dest="app_version",
155
+ action="store_true",
156
+ default=False,
157
+ help="print the AppIntel version",
158
+ )
159
+ return parser
160
+
161
+
162
+ def main(argv: list[str] | None = None) -> int:
163
+ args = build_parser().parse_args(argv)
164
+
165
+ if not args.logo_off:
166
+ print(logo)
167
+ if args.app_version:
168
+ print(f"Current version: {__version__}")
169
+ return 0
170
+
171
+ response = get_content(args.search_term, args.store_country, args.category_location)
172
+ jsondata = response.json()
173
+
174
+ if args.print_me:
175
+ pprint(jsondata)
176
+ for key in jsondata.get("results", [{}])[0]:
177
+ print(f"{key}:")
178
+ return 0
179
+
180
+ average_price = get_mean(jsondata)
181
+ max_price = get_max(jsondata)
182
+ min_price = get_min(jsondata)
183
+ median_price = get_median(jsondata)
184
+
185
+ print("Results of the query")
186
+ print("*****" * 5)
187
+ print(
188
+ f"The average price of the \033[94m{jsondata.get('resultCount', 0)}\033[0m items matching search term "
189
+ f"\033[92m{args.search_term}\033[0m: ${average_price:.2f}, the median is \033[94m{median_price:.2f}\033[0m, "
190
+ f"the min is \033[94m{min_price:.2f}\033[0m, and the max is \033[94m{max_price:.2f}\033[0m"
191
+ )
192
+ print("")
193
+
194
+ if args.output_table:
195
+ print(format_table(jsondata.get("results", [])))
196
+ else:
197
+ filename = f"{args.search_term}.json"
198
+ with open(filename, "w", encoding="utf-8") as file:
199
+ json.dump(response.json(), file, indent=2)
200
+ print(f"file saved as {filename}")
201
+ return 0
202
+
203
+
204
+ if __name__ == "__main__":
205
+ raise SystemExit(main())
@@ -0,0 +1,4 @@
1
+ digraph "classes" {
2
+ charset="utf-8"
3
+ rankdir=BT
4
+ }