site-session-auto 0.1.0__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.
- site_session_auto-0.1.0/PKG-INFO +7 -0
- site_session_auto-0.1.0/pyproject.toml +17 -0
- site_session_auto-0.1.0/setup.cfg +4 -0
- site_session_auto-0.1.0/site_session_auto/__init__.py +1 -0
- site_session_auto-0.1.0/site_session_auto/__main__.py +3 -0
- site_session_auto-0.1.0/site_session_auto/cli.py +153 -0
- site_session_auto-0.1.0/site_session_auto.egg-info/PKG-INFO +7 -0
- site_session_auto-0.1.0/site_session_auto.egg-info/SOURCES.txt +9 -0
- site_session_auto-0.1.0/site_session_auto.egg-info/dependency_links.txt +1 -0
- site_session_auto-0.1.0/site_session_auto.egg-info/entry_points.txt +2 -0
- site_session_auto-0.1.0/site_session_auto.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "site-session-auto"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Restores your last browser session with one command, Browser never does this."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
site-session-auto = "site_session_auto.cli:main"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
include = ["site_session_auto*"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""
|
|
2
|
+
site-session-auto — restore your last browser session with one command.
|
|
3
|
+
|
|
4
|
+
Saves open tabs to last_session.json and reopens them on demand,
|
|
5
|
+
overriding any browser start page (GX Corner, we're looking at you).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
import webbrowser
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
CONFIG_DIR = Path(os.environ.get("APPDATA", Path.home())) / "site_session_auto"
|
|
15
|
+
SESSION_FILE = CONFIG_DIR / "last_session.json"
|
|
16
|
+
|
|
17
|
+
BROWSERS = {
|
|
18
|
+
"opera": r"C:\Users\%USERNAME%\AppData\Local\Programs\Opera\opera.exe",
|
|
19
|
+
"opera_gx": r"C:\Users\%USERNAME%\AppData\Local\Programs\Opera GX\opera.exe",
|
|
20
|
+
"chrome": r"C:\Program Files\Google\Chrome\Application\chrome.exe",
|
|
21
|
+
"firefox": r"C:\Program Files\Mozilla Firefox\firefox.exe",
|
|
22
|
+
"edge": r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe",
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
BANNER = "[SSA] site-session-auto v0.1.0 | save | restore | list | clear"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _expand(path: str) -> str:
|
|
29
|
+
return path.replace("%USERNAME%", os.environ.get("USERNAME", ""))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def load_session() -> dict:
|
|
33
|
+
if SESSION_FILE.exists():
|
|
34
|
+
try:
|
|
35
|
+
return json.loads(SESSION_FILE.read_text(encoding="utf-8"))
|
|
36
|
+
except (json.JSONDecodeError, OSError):
|
|
37
|
+
return {}
|
|
38
|
+
return {}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def save_session(urls: list, browser: str = None) -> None:
|
|
42
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
43
|
+
data = {
|
|
44
|
+
"urls": urls,
|
|
45
|
+
"browser": browser,
|
|
46
|
+
"saved_at": __import__("datetime").datetime.now().isoformat(timespec="seconds"),
|
|
47
|
+
}
|
|
48
|
+
SESSION_FILE.write_text(json.dumps(data, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def cmd_save(args) -> int:
|
|
52
|
+
if not args:
|
|
53
|
+
print("[SSA] usage: site-session-auto save <url> [url2 ...] [--browser opera_gx]")
|
|
54
|
+
return 1
|
|
55
|
+
browser = None
|
|
56
|
+
if "--browser" in args:
|
|
57
|
+
i = args.index("--browser")
|
|
58
|
+
browser = args[i + 1] if i + 1 < len(args) else None
|
|
59
|
+
args = args[:i] + args[i + 2:]
|
|
60
|
+
urls = [u for u in args if u.startswith(("http://", "https://"))]
|
|
61
|
+
if not urls:
|
|
62
|
+
print("[SSA] no valid urls found (must start with http:// or https://)")
|
|
63
|
+
return 1
|
|
64
|
+
save_session(urls, browser)
|
|
65
|
+
print(f"[SSA] session saved: {len(urls)} tab(s) -> {SESSION_FILE}")
|
|
66
|
+
for u in urls:
|
|
67
|
+
print(f"[SSA] + {u}")
|
|
68
|
+
return 0
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def cmd_restore(args) -> int:
|
|
72
|
+
session = load_session()
|
|
73
|
+
urls = session.get("urls", [])
|
|
74
|
+
if not urls:
|
|
75
|
+
print("[SSA] no saved session found. save one first: site-session-auto save <url>")
|
|
76
|
+
return 1
|
|
77
|
+
|
|
78
|
+
browser = session.get("browser")
|
|
79
|
+
if "--browser" in args:
|
|
80
|
+
i = args.index("--browser")
|
|
81
|
+
browser = args[i + 1] if i + 1 < len(args) else browser
|
|
82
|
+
args = args[:i] + args[i + 2:]
|
|
83
|
+
if args: # extra urls passed inline -> append to saved session
|
|
84
|
+
urls = urls + [u for u in args if u.startswith(("http://", "https://"))]
|
|
85
|
+
|
|
86
|
+
print(f"[SSA] restoring session: {len(urls)} tab(s)")
|
|
87
|
+
for u in urls:
|
|
88
|
+
print(f"[SSA] -> {u}")
|
|
89
|
+
|
|
90
|
+
if browser and browser.lower() in BROWSERS:
|
|
91
|
+
exe = _expand(BROWSERS[browser.lower()])
|
|
92
|
+
if Path(exe).exists():
|
|
93
|
+
# open all tabs in the target browser
|
|
94
|
+
import subprocess
|
|
95
|
+
subprocess.Popen([exe] + urls)
|
|
96
|
+
print(f"[SSA] launched in {browser}")
|
|
97
|
+
return 0
|
|
98
|
+
print(f"[SSA] browser not found at {exe}, falling back to default")
|
|
99
|
+
|
|
100
|
+
webbrowser.open(urls[0])
|
|
101
|
+
for u in urls[1:]:
|
|
102
|
+
webbrowser.open_new_tab(u)
|
|
103
|
+
print("[SSA] launched in default browser")
|
|
104
|
+
return 0
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def cmd_list(args) -> int:
|
|
108
|
+
session = load_session()
|
|
109
|
+
if not session.get("urls"):
|
|
110
|
+
print("[SSA] session is empty")
|
|
111
|
+
return 0
|
|
112
|
+
print(f"[SSA] saved at {session.get('saved_at', '?')}")
|
|
113
|
+
print(f"[SSA] browser: {session.get('browser') or 'default'}")
|
|
114
|
+
for i, u in enumerate(session["urls"], 1):
|
|
115
|
+
print(f"[SSA] {i}. {u}")
|
|
116
|
+
return 0
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def cmd_clear(args) -> int:
|
|
120
|
+
if SESSION_FILE.exists():
|
|
121
|
+
SESSION_FILE.unlink()
|
|
122
|
+
print("[SSA] session cleared. the past is officially over")
|
|
123
|
+
else:
|
|
124
|
+
print("[SSA] nothing to clear")
|
|
125
|
+
return 0
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def main() -> None:
|
|
129
|
+
print(BANNER)
|
|
130
|
+
args = sys.argv[1:]
|
|
131
|
+
if not args or args[0] in ("restore", "r", "open"):
|
|
132
|
+
sys.exit(cmd_restore(args[1:]))
|
|
133
|
+
elif args[0] == "save" and args[1:] == ["-"]:
|
|
134
|
+
# read urls from stdin: site-session-auto save -
|
|
135
|
+
urls = [line.strip() for line in sys.stdin if line.strip()]
|
|
136
|
+
sys.exit(cmd_save(urls))
|
|
137
|
+
elif args[0] == "save" or args[0] == "s":
|
|
138
|
+
sys.exit(cmd_save(args[1:]))
|
|
139
|
+
elif args[0] == "list" or args[0] == "l":
|
|
140
|
+
sys.exit(cmd_list(args[1:]))
|
|
141
|
+
elif args[0] == "clear" or args[0] == "c":
|
|
142
|
+
sys.exit(cmd_clear(args[1:]))
|
|
143
|
+
elif args[0] in ("-h", "--help", "help"):
|
|
144
|
+
print(__doc__)
|
|
145
|
+
print("usage: site-session-auto [save <url>... | restore | list | clear] [--browser name]")
|
|
146
|
+
sys.exit(0)
|
|
147
|
+
else:
|
|
148
|
+
print(f"[SSA] unknown command: {args[0]}")
|
|
149
|
+
sys.exit(1)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if __name__ == "__main__":
|
|
153
|
+
main()
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
site_session_auto/__init__.py
|
|
3
|
+
site_session_auto/__main__.py
|
|
4
|
+
site_session_auto/cli.py
|
|
5
|
+
site_session_auto.egg-info/PKG-INFO
|
|
6
|
+
site_session_auto.egg-info/SOURCES.txt
|
|
7
|
+
site_session_auto.egg-info/dependency_links.txt
|
|
8
|
+
site_session_auto.egg-info/entry_points.txt
|
|
9
|
+
site_session_auto.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
site_session_auto
|