Skip to content

Commit

Permalink
git
Browse files Browse the repository at this point in the history
  • Loading branch information
moqsien committed Jun 7, 2023
1 parent 293a8ce commit 5c7aa56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
10 changes: 9 additions & 1 deletion free/common/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class Config(object):
def __init__(self, file_path:str=""):
self.dir: str = file_path if file_path else os.getcwd()
self.path = os.path.join(self.dir, "free_vpn_config.json")
print(self.path)
self.dict: dict = dict()
self.load()
if len(self.dict) > 0:
self._key = self.dict.get("key", "x^)dixf&*1$free]")
self._store_dir = self.dict.get("store_dir", os.getcwd())
self._proxy = self.dict.get("proxy", "http://localhost:2019")
else:
self.set_config()
store_dir = getattr(self, "store_dir")
Expand All @@ -31,12 +31,16 @@ def save(self):
def set_config(self):
self._key = input("Set encryption key:\n").strip(" ")
self._store_dir = input("Set restore directory:\n").strip(" ")
self._proxy = input("Set local proxy:\n").strip(" ")
if len(self.key) != 16:
self._key = "x^)dixf&*1$free]"
if not os.path.exists(self.store_dir):
self._store_dir = os.getcwd()
if not self._proxy:
self._proxy = "http://localhost:2019"
self.dict["key"] = self._key
self.dict["store_dir"] = self._store_dir
self.dict["proxy"] = self._proxy
self.save()

@property
Expand All @@ -46,6 +50,10 @@ def key(self):
@property
def store_dir(self):
return self._store_dir

@property
def proxy(self):
return self._proxy

if __name__ == "__main__":
# TODO: config file stored to current working directory.
Expand Down
9 changes: 5 additions & 4 deletions free/sites/geoinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
class DownloadGeoInfo(object):
def __init__(self):
self.urls = geoinfo_download_urls
self.store_dir = os.environ.get(STORE_DIR_ENV_NAME)
if not self.store_dir:
self.store_dir = os.path.abspath(".")

def parse(self)->str:
store_dir = os.environ.get(STORE_DIR_ENV_NAME)
if not store_dir:
store_dir = os.getcwd()

for name, url in self.urls.items():
print(f"Downloading {name}...")
resp = requests.get(url)
with open(os.path.join(self.store_dir, name), 'wb') as f:
with open(os.path.join(store_dir, name), 'wb') as f:
f.write(resp.content)
return ""

Expand Down
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self):
self.conf = Config()
self.store_dir = self.conf.store_dir
self.key = self.conf.key
if self.conf.proxy:
set_proxy(self.conf.proxy)

def parse_other(self, line:str):
if line.find("vmess://"):
Expand Down Expand Up @@ -97,6 +99,7 @@ def run(self):
else:
self.parse(content)
if any([self.vmess, self.vless, self.ss, self.ssr, self.trojan]):
print(f"Download VPNs Statistics: vmess[{len(self.vmess)}] vless[{len(self.vless)}] ss[{len(self.ss)}] ssr[{len(self.ssr)}] trojan[{len(self.trojan)}]\n")
self.save_file("vpn.json")
self.git_push()

Expand Down Expand Up @@ -130,8 +133,5 @@ def git_push(self):


if __name__ == "__main__":
# TODO: add config file and auto git push.
if not get_proxy():
set_proxy("http://localhost:2019")
v = VPN()
v.run()

0 comments on commit 5c7aa56

Please sign in to comment.