creddit 0.0.1__tar.gz → 0.0.2__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.
- {creddit-0.0.1 → creddit-0.0.2}/LICENSE +9 -9
- {creddit-0.0.1 → creddit-0.0.2}/PKG-INFO +57 -57
- {creddit-0.0.1 → creddit-0.0.2}/README.md +43 -43
- {creddit-0.0.1 → creddit-0.0.2}/pyproject.toml +33 -32
- {creddit-0.0.1 → creddit-0.0.2}/setup.cfg +4 -4
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit/__init__.py +5 -5
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit/__main__.py +4 -4
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit/config.py +113 -113
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit/reddit.py +123 -123
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit/terminal.py +367 -367
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit.egg-info/PKG-INFO +57 -57
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit/py.typed +0 -0
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit.egg-info/SOURCES.txt +0 -0
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit.egg-info/dependency_links.txt +0 -0
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit.egg-info/requires.txt +0 -0
- {creddit-0.0.1 → creddit-0.0.2}/src/creddit.egg-info/top_level.txt +0 -0
@@ -1,9 +1,9 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c)
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
-
|
7
|
-
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
8
|
-
|
9
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Vishal N
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,57 +1,57 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: creddit
|
3
|
-
Version: 0.0.
|
4
|
-
Summary: An unofficial cli client for Reddit, aimed at people who regularly browse specific subreddits or topics instead of reading the homepage (r/all).
|
5
|
-
Author-email: Vishal Nandagopal <dev@vishalnandagopal.com>
|
6
|
-
License-Expression: MIT
|
7
|
-
Requires-Python: >=3.13
|
8
|
-
Description-Content-Type: text/markdown
|
9
|
-
License-File: LICENSE
|
10
|
-
Requires-Dist: colorama>=0.4.6
|
11
|
-
Requires-Dist: python-dotenv>=1.1.0
|
12
|
-
Requires-Dist: requests>=2.32.3
|
13
|
-
Dynamic: license-file
|
14
|
-
|
15
|
-
# creddit - A CLI client for Reddit
|
16
|
-
|
17
|
-
An unofficial cli client for Reddit, aimed at people who regularly browse specific subreddits or topics instead of reading the homepage (r/all).
|
18
|
-
|
19
|
-
### Features:
|
20
|
-
|
21
|
-
- Distraction free. Can browse a few posts and continue with your day. No flashy gifs, awards, ads or posts.
|
22
|
-
|
23
|
-
- Browse a subreddit by entering just the name.
|
24
|
-
|
25
|
-
- Prints a link to the article mentioned in every post, for you to continue reading it in your browser (`ctrl+click`), in case you are interested.
|
26
|
-
|
27
|
-
- Can browse top comments for every post just by entering the number shown beside the post in the terminal.
|
28
|
-
|
29
|
-
Feel free to send a PR with any additional features, or make an issue if you have any feature requests!
|
30
|
-
|
31
|
-
This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
|
32
|
-
|
33
|
-
### How to use?
|
34
|
-
|
35
|
-
Clone the repo and install the thing as a package
|
36
|
-
|
37
|
-
```sh
|
38
|
-
git clone --depth 1 https://github.com/vishalnandagopal/creddit/ creddit
|
39
|
-
cd creddit
|
40
|
-
pip install uv
|
41
|
-
uv sync
|
42
|
-
uv build
|
43
|
-
pip install ./dist/creddit-1.0.0-py3-none-any.whl
|
44
|
-
```
|
45
|
-
|
46
|
-
And to finally run it,
|
47
|
-
|
48
|
-
```sh
|
49
|
-
python -m creddit
|
50
|
-
```
|
51
|
-
|
52
|
-
### Features to add
|
53
|
-
|
54
|
-
- Publish to pip
|
55
|
-
- More guidance on MPV, and alternatives if it isn't installed
|
56
|
-
|
57
|
-
(Copyright (c)
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: creddit
|
3
|
+
Version: 0.0.2
|
4
|
+
Summary: An unofficial cli client for Reddit, aimed at people who regularly browse specific subreddits or topics instead of reading the homepage (r/all).
|
5
|
+
Author-email: Vishal Nandagopal <dev@vishalnandagopal.com>
|
6
|
+
License-Expression: MIT
|
7
|
+
Requires-Python: >=3.13
|
8
|
+
Description-Content-Type: text/markdown
|
9
|
+
License-File: LICENSE
|
10
|
+
Requires-Dist: colorama>=0.4.6
|
11
|
+
Requires-Dist: python-dotenv>=1.1.0
|
12
|
+
Requires-Dist: requests>=2.32.3
|
13
|
+
Dynamic: license-file
|
14
|
+
|
15
|
+
# creddit - A CLI client for Reddit
|
16
|
+
|
17
|
+
An unofficial cli client for Reddit, aimed at people who regularly browse specific subreddits or topics instead of reading the homepage (r/all).
|
18
|
+
|
19
|
+
### Features:
|
20
|
+
|
21
|
+
- Distraction free. Can browse a few posts and continue with your day. No flashy gifs, awards, ads or posts.
|
22
|
+
|
23
|
+
- Browse a subreddit by entering just the name.
|
24
|
+
|
25
|
+
- Prints a link to the article mentioned in every post, for you to continue reading it in your browser (`ctrl+click`), in case you are interested.
|
26
|
+
|
27
|
+
- Can browse top comments for every post just by entering the number shown beside the post in the terminal.
|
28
|
+
|
29
|
+
Feel free to send a PR with any additional features, or make an issue if you have any feature requests!
|
30
|
+
|
31
|
+
This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
|
32
|
+
|
33
|
+
### How to use?
|
34
|
+
|
35
|
+
Clone the repo and install the thing as a package
|
36
|
+
|
37
|
+
```sh
|
38
|
+
git clone --depth 1 https://github.com/vishalnandagopal/creddit/ creddit
|
39
|
+
cd creddit
|
40
|
+
pip install uv
|
41
|
+
uv sync
|
42
|
+
uv build
|
43
|
+
pip install ./dist/creddit-1.0.0-py3-none-any.whl
|
44
|
+
```
|
45
|
+
|
46
|
+
And to finally run it,
|
47
|
+
|
48
|
+
```sh
|
49
|
+
python -m creddit
|
50
|
+
```
|
51
|
+
|
52
|
+
### Features to add
|
53
|
+
|
54
|
+
- Publish to pip
|
55
|
+
- More guidance on MPV, and alternatives if it isn't installed
|
56
|
+
|
57
|
+
(Copyright (c) 2025 Vishal N)
|
@@ -1,43 +1,43 @@
|
|
1
|
-
# creddit - A CLI client for Reddit
|
2
|
-
|
3
|
-
An unofficial cli client for Reddit, aimed at people who regularly browse specific subreddits or topics instead of reading the homepage (r/all).
|
4
|
-
|
5
|
-
### Features:
|
6
|
-
|
7
|
-
- Distraction free. Can browse a few posts and continue with your day. No flashy gifs, awards, ads or posts.
|
8
|
-
|
9
|
-
- Browse a subreddit by entering just the name.
|
10
|
-
|
11
|
-
- Prints a link to the article mentioned in every post, for you to continue reading it in your browser (`ctrl+click`), in case you are interested.
|
12
|
-
|
13
|
-
- Can browse top comments for every post just by entering the number shown beside the post in the terminal.
|
14
|
-
|
15
|
-
Feel free to send a PR with any additional features, or make an issue if you have any feature requests!
|
16
|
-
|
17
|
-
This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
|
18
|
-
|
19
|
-
### How to use?
|
20
|
-
|
21
|
-
Clone the repo and install the thing as a package
|
22
|
-
|
23
|
-
```sh
|
24
|
-
git clone --depth 1 https://github.com/vishalnandagopal/creddit/ creddit
|
25
|
-
cd creddit
|
26
|
-
pip install uv
|
27
|
-
uv sync
|
28
|
-
uv build
|
29
|
-
pip install ./dist/creddit-1.0.0-py3-none-any.whl
|
30
|
-
```
|
31
|
-
|
32
|
-
And to finally run it,
|
33
|
-
|
34
|
-
```sh
|
35
|
-
python -m creddit
|
36
|
-
```
|
37
|
-
|
38
|
-
### Features to add
|
39
|
-
|
40
|
-
- Publish to pip
|
41
|
-
- More guidance on MPV, and alternatives if it isn't installed
|
42
|
-
|
43
|
-
(Copyright (c)
|
1
|
+
# creddit - A CLI client for Reddit
|
2
|
+
|
3
|
+
An unofficial cli client for Reddit, aimed at people who regularly browse specific subreddits or topics instead of reading the homepage (r/all).
|
4
|
+
|
5
|
+
### Features:
|
6
|
+
|
7
|
+
- Distraction free. Can browse a few posts and continue with your day. No flashy gifs, awards, ads or posts.
|
8
|
+
|
9
|
+
- Browse a subreddit by entering just the name.
|
10
|
+
|
11
|
+
- Prints a link to the article mentioned in every post, for you to continue reading it in your browser (`ctrl+click`), in case you are interested.
|
12
|
+
|
13
|
+
- Can browse top comments for every post just by entering the number shown beside the post in the terminal.
|
14
|
+
|
15
|
+
Feel free to send a PR with any additional features, or make an issue if you have any feature requests!
|
16
|
+
|
17
|
+
This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree.
|
18
|
+
|
19
|
+
### How to use?
|
20
|
+
|
21
|
+
Clone the repo and install the thing as a package
|
22
|
+
|
23
|
+
```sh
|
24
|
+
git clone --depth 1 https://github.com/vishalnandagopal/creddit/ creddit
|
25
|
+
cd creddit
|
26
|
+
pip install uv
|
27
|
+
uv sync
|
28
|
+
uv build
|
29
|
+
pip install ./dist/creddit-1.0.0-py3-none-any.whl
|
30
|
+
```
|
31
|
+
|
32
|
+
And to finally run it,
|
33
|
+
|
34
|
+
```sh
|
35
|
+
python -m creddit
|
36
|
+
```
|
37
|
+
|
38
|
+
### Features to add
|
39
|
+
|
40
|
+
- Publish to pip
|
41
|
+
- More guidance on MPV, and alternatives if it isn't installed
|
42
|
+
|
43
|
+
(Copyright (c) 2025 Vishal N)
|
@@ -1,32 +1,33 @@
|
|
1
|
-
[project]
|
2
|
-
name = "creddit"
|
3
|
-
version = "0.0.
|
4
|
-
description = "An unofficial cli client for Reddit, aimed at people who regularly browse specific subreddits or topics instead of reading the homepage (r/all)."
|
5
|
-
authors = [
|
6
|
-
{name = "Vishal Nandagopal", email="dev@vishalnandagopal.com"}
|
7
|
-
]
|
8
|
-
license = "MIT"
|
9
|
-
readme = "README.md"
|
10
|
-
requires-python = ">=3.13"
|
11
|
-
dependencies = [
|
12
|
-
"colorama>=0.4.6",
|
13
|
-
"python-dotenv>=1.1.0",
|
14
|
-
"requests>=2.32.3",
|
15
|
-
]
|
16
|
-
|
17
|
-
[dependency-groups]
|
18
|
-
dev = [
|
19
|
-
"mypy>=1.15.0",
|
20
|
-
"ruff>=0.11.9",
|
21
|
-
"ty>=0.0.0a8",
|
22
|
-
"types-colorama>=0.4.15.20240311",
|
23
|
-
"types-requests>=2.32.0.20250328",
|
24
|
-
]
|
25
|
-
|
26
|
-
|
27
|
-
[tool.uv]
|
28
|
-
required-environments = [
|
29
|
-
"sys_platform == 'darwin'",
|
30
|
-
"sys_platform == 'linux'",
|
31
|
-
"sys_platform == 'windows'"
|
32
|
-
]
|
1
|
+
[project]
|
2
|
+
name = "creddit"
|
3
|
+
version = "0.0.2"
|
4
|
+
description = "An unofficial cli client for Reddit, aimed at people who regularly browse specific subreddits or topics instead of reading the homepage (r/all)."
|
5
|
+
authors = [
|
6
|
+
{name = "Vishal Nandagopal", email="dev@vishalnandagopal.com"}
|
7
|
+
]
|
8
|
+
license = "MIT"
|
9
|
+
readme = "README.md"
|
10
|
+
requires-python = ">=3.13"
|
11
|
+
dependencies = [
|
12
|
+
"colorama>=0.4.6",
|
13
|
+
"python-dotenv>=1.1.0",
|
14
|
+
"requests>=2.32.3",
|
15
|
+
]
|
16
|
+
|
17
|
+
[dependency-groups]
|
18
|
+
dev = [
|
19
|
+
"mypy>=1.15.0",
|
20
|
+
"ruff>=0.11.9",
|
21
|
+
"ty>=0.0.0a8",
|
22
|
+
"types-colorama>=0.4.15.20240311",
|
23
|
+
"types-requests>=2.32.0.20250328",
|
24
|
+
]
|
25
|
+
|
26
|
+
|
27
|
+
[tool.uv]
|
28
|
+
required-environments = [
|
29
|
+
"sys_platform == 'darwin'",
|
30
|
+
"sys_platform == 'linux'",
|
31
|
+
"sys_platform == 'windows'"
|
32
|
+
]
|
33
|
+
required-version = ">=0.7"
|
@@ -1,4 +1,4 @@
|
|
1
|
-
[egg_info]
|
2
|
-
tag_build =
|
3
|
-
tag_date = 0
|
4
|
-
|
1
|
+
[egg_info]
|
2
|
+
tag_build =
|
3
|
+
tag_date = 0
|
4
|
+
|
@@ -1,5 +1,5 @@
|
|
1
|
-
"""
|
2
|
-
creddit - A CLI client for Reddit
|
3
|
-
"""
|
4
|
-
|
5
|
-
from .terminal import run as run
|
1
|
+
"""
|
2
|
+
creddit - A CLI client for Reddit
|
3
|
+
"""
|
4
|
+
|
5
|
+
from .terminal import run as run
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from creddit.terminal import run
|
2
|
-
|
3
|
-
if __name__ == "__main__":
|
4
|
-
run()
|
1
|
+
from creddit.terminal import run
|
2
|
+
|
3
|
+
if __name__ == "__main__":
|
4
|
+
run()
|
@@ -1,113 +1,113 @@
|
|
1
|
-
"""
|
2
|
-
A file that stores all the variables that much be read from the env file. Helps me keep track of them at one place, instead of reading and using them where they are needed. This application relies on env for config.
|
3
|
-
|
4
|
-
Config is store in a JSON file. TOML, YAML, and ini were options but
|
5
|
-
|
6
|
-
TOML - built in library can't write. Don't want to package another module.
|
7
|
-
YAML - Built in and ugly
|
8
|
-
.ini - Ugly
|
9
|
-
|
10
|
-
"""
|
11
|
-
|
12
|
-
from json import JSONDecodeError
|
13
|
-
from json import dump as json_dump
|
14
|
-
from json import load as json_load
|
15
|
-
from os import getenv
|
16
|
-
from pathlib import Path
|
17
|
-
from sys import platform
|
18
|
-
from typing import Literal, NotRequired, TypedDict
|
19
|
-
|
20
|
-
|
21
|
-
class Config(TypedDict):
|
22
|
-
ignored_users: list[str]
|
23
|
-
no_of_posts_to_print: int
|
24
|
-
ignore_all_mod_posts: bool
|
25
|
-
default_subreddit: NotRequired[str]
|
26
|
-
|
27
|
-
|
28
|
-
default_config: Config = {
|
29
|
-
"ignored_users": ["2soccer2bot", "AutoModerator"],
|
30
|
-
"no_of_posts_to_print": 10,
|
31
|
-
"ignore_all_mod_posts": True,
|
32
|
-
}
|
33
|
-
|
34
|
-
config_folder: Path
|
35
|
-
|
36
|
-
if platform == "win32":
|
37
|
-
config_folder = Path(getenv("LOCALAPPDATA", "./config/"))
|
38
|
-
elif platform == "darwin":
|
39
|
-
config_folder = Path("~/Library/Application Support/")
|
40
|
-
elif platform == "linux":
|
41
|
-
config_folder = Path("~/.config/")
|
42
|
-
else:
|
43
|
-
config_folder = Path("./config/")
|
44
|
-
|
45
|
-
config_folder = config_folder / "creddit"
|
46
|
-
config_folder.mkdir(parents=True, exist_ok=True)
|
47
|
-
|
48
|
-
# It's actually a cursed thing that you can divide paths.
|
49
|
-
config_path: Path = config_folder / "config.json"
|
50
|
-
"""The path of the config"""
|
51
|
-
|
52
|
-
|
53
|
-
def check_config_existence() -> bool:
|
54
|
-
"""Checks if a config file exists, and that it valid
|
55
|
-
|
56
|
-
Returns:
|
57
|
-
bool: True if file exists and contains all required keys
|
58
|
-
"""
|
59
|
-
if not Path(config_path).exists():
|
60
|
-
return False
|
61
|
-
|
62
|
-
with open(config_path, "r") as f:
|
63
|
-
try:
|
64
|
-
config = json_load(f)
|
65
|
-
except JSONDecodeError:
|
66
|
-
return False
|
67
|
-
if not (config or (default_config.keys() < config.keys())):
|
68
|
-
return False
|
69
|
-
|
70
|
-
return True
|
71
|
-
|
72
|
-
|
73
|
-
def read_config(config_path: Path = config_path) -> Config:
|
74
|
-
"""Read the config file"""
|
75
|
-
|
76
|
-
with open(config_path, "r") as f:
|
77
|
-
config: Config = json_load(f)
|
78
|
-
|
79
|
-
required_keys = default_config.keys()
|
80
|
-
|
81
|
-
if required_keys <= config.keys():
|
82
|
-
# Looks like all keys are present
|
83
|
-
return config
|
84
|
-
|
85
|
-
raise RuntimeError("Looks like some values in the config file are missing")
|
86
|
-
|
87
|
-
|
88
|
-
def create_config(c: dict | Config = default_config) -> bool:
|
89
|
-
required_keys = default_config.keys()
|
90
|
-
|
91
|
-
if required_keys <= c.keys():
|
92
|
-
# All the must have keys are present
|
93
|
-
with open(config_path, "w+") as f:
|
94
|
-
json_dump(c, f, indent=4, sort_keys=True)
|
95
|
-
return True
|
96
|
-
|
97
|
-
return False
|
98
|
-
|
99
|
-
|
100
|
-
def edit_config(new_config: dict) -> bool:
|
101
|
-
c = read_config()
|
102
|
-
key: Literal[
|
103
|
-
"ignored_users",
|
104
|
-
"no_of_posts_to_print",
|
105
|
-
"ignore_all_mod_posts",
|
106
|
-
"default_subreddit",
|
107
|
-
]
|
108
|
-
for key in new_config:
|
109
|
-
c[key] = new_config[key]
|
110
|
-
with open(config_path, "w") as f:
|
111
|
-
json_dump(c, f, indent=4, sort_keys=True)
|
112
|
-
return True
|
113
|
-
return False
|
1
|
+
"""
|
2
|
+
A file that stores all the variables that much be read from the env file. Helps me keep track of them at one place, instead of reading and using them where they are needed. This application relies on env for config.
|
3
|
+
|
4
|
+
Config is store in a JSON file. TOML, YAML, and ini were options but
|
5
|
+
|
6
|
+
TOML - built in library can't write. Don't want to package another module.
|
7
|
+
YAML - Built in and ugly
|
8
|
+
.ini - Ugly
|
9
|
+
|
10
|
+
"""
|
11
|
+
|
12
|
+
from json import JSONDecodeError
|
13
|
+
from json import dump as json_dump
|
14
|
+
from json import load as json_load
|
15
|
+
from os import getenv
|
16
|
+
from pathlib import Path
|
17
|
+
from sys import platform
|
18
|
+
from typing import Literal, NotRequired, TypedDict
|
19
|
+
|
20
|
+
|
21
|
+
class Config(TypedDict):
|
22
|
+
ignored_users: list[str]
|
23
|
+
no_of_posts_to_print: int
|
24
|
+
ignore_all_mod_posts: bool
|
25
|
+
default_subreddit: NotRequired[str]
|
26
|
+
|
27
|
+
|
28
|
+
default_config: Config = {
|
29
|
+
"ignored_users": ["2soccer2bot", "AutoModerator"],
|
30
|
+
"no_of_posts_to_print": 10,
|
31
|
+
"ignore_all_mod_posts": True,
|
32
|
+
}
|
33
|
+
|
34
|
+
config_folder: Path
|
35
|
+
|
36
|
+
if platform == "win32":
|
37
|
+
config_folder = Path(getenv("LOCALAPPDATA", "./config/"))
|
38
|
+
elif platform == "darwin":
|
39
|
+
config_folder = Path("~/Library/Application Support/")
|
40
|
+
elif platform == "linux":
|
41
|
+
config_folder = Path("~/.config/")
|
42
|
+
else:
|
43
|
+
config_folder = Path("./config/")
|
44
|
+
|
45
|
+
config_folder = config_folder / "creddit"
|
46
|
+
config_folder.mkdir(parents=True, exist_ok=True)
|
47
|
+
|
48
|
+
# It's actually a cursed thing that you can divide paths.
|
49
|
+
config_path: Path = config_folder / "config.json"
|
50
|
+
"""The path of the config"""
|
51
|
+
|
52
|
+
|
53
|
+
def check_config_existence() -> bool:
|
54
|
+
"""Checks if a config file exists, and that it valid
|
55
|
+
|
56
|
+
Returns:
|
57
|
+
bool: True if file exists and contains all required keys
|
58
|
+
"""
|
59
|
+
if not Path(config_path).exists():
|
60
|
+
return False
|
61
|
+
|
62
|
+
with open(config_path, "r") as f:
|
63
|
+
try:
|
64
|
+
config = json_load(f)
|
65
|
+
except JSONDecodeError:
|
66
|
+
return False
|
67
|
+
if not (config or (default_config.keys() < config.keys())):
|
68
|
+
return False
|
69
|
+
|
70
|
+
return True
|
71
|
+
|
72
|
+
|
73
|
+
def read_config(config_path: Path = config_path) -> Config:
|
74
|
+
"""Read the config file"""
|
75
|
+
|
76
|
+
with open(config_path, "r") as f:
|
77
|
+
config: Config = json_load(f)
|
78
|
+
|
79
|
+
required_keys = default_config.keys()
|
80
|
+
|
81
|
+
if required_keys <= config.keys():
|
82
|
+
# Looks like all keys are present
|
83
|
+
return config
|
84
|
+
|
85
|
+
raise RuntimeError("Looks like some values in the config file are missing")
|
86
|
+
|
87
|
+
|
88
|
+
def create_config(c: dict | Config = default_config) -> bool:
|
89
|
+
required_keys = default_config.keys()
|
90
|
+
|
91
|
+
if required_keys <= c.keys():
|
92
|
+
# All the must have keys are present
|
93
|
+
with open(config_path, "w+") as f:
|
94
|
+
json_dump(c, f, indent=4, sort_keys=True)
|
95
|
+
return True
|
96
|
+
|
97
|
+
return False
|
98
|
+
|
99
|
+
|
100
|
+
def edit_config(new_config: dict) -> bool:
|
101
|
+
c = read_config()
|
102
|
+
key: Literal[
|
103
|
+
"ignored_users",
|
104
|
+
"no_of_posts_to_print",
|
105
|
+
"ignore_all_mod_posts",
|
106
|
+
"default_subreddit",
|
107
|
+
]
|
108
|
+
for key in new_config:
|
109
|
+
c[key] = new_config[key]
|
110
|
+
with open(config_path, "w") as f:
|
111
|
+
json_dump(c, f, indent=4, sort_keys=True)
|
112
|
+
return True
|
113
|
+
return False
|