From fad8337541bb0935e059351d82d64c5b32d8c96d Mon Sep 17 00:00:00 2001 From: mmalter Date: Tue, 20 Aug 2024 00:12:28 +0200 Subject: [PATCH] First implementation --- LICENSE | 2 +- grattoir/__init__.py | 40 ++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 18 ++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 grattoir/__init__.py create mode 100644 pyproject.toml diff --git a/LICENSE b/LICENSE index 994f786..bc5b9e4 100644 --- a/LICENSE +++ b/LICENSE @@ -219,7 +219,7 @@ If you develop a new program, and you want it to be of the greatest possible use To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. - grattoir + gerold Copyright (C) 2024 mmalter This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. diff --git a/grattoir/__init__.py b/grattoir/__init__.py new file mode 100644 index 0000000..e97b6dd --- /dev/null +++ b/grattoir/__init__.py @@ -0,0 +1,40 @@ +from selenium.webdriver import firefox +from fake_useragent import UserAgent +from pathlib import Path +import os + + +def tor_profile(): + tor_firefox_path = str(Path("~/.tor project/firefox").expanduser()) + ini_path = tor_firefox_path + "/profiles.ini" + with open(ini_path) as ini: + for line in ini: + if "Path=" in line: + return tor_firefox_path + '/' + line.split('=')[1][:-1] + + +def tor_browser_binary_path(): + for pe in os.environ["PATH"].split(os.pathsep): + checkname = os.path.join(pe, "tor-browser") + if os.access(checkname, os.X_OK) and not os.path.isdir(checkname): + return checkname + return None + + +class Grattoir(object): + def __init__(self): + self._driver = None + + def __enter__(self): + p_path = tor_profile() + profile = firefox.firefox_profile.FirefoxProfile(profile_directory=p_path) + b_path = tor_browser_binary_path() + binary = firefox.firefox_binary.FirefoxBinary(firefox_path=b_path) + o = firefox.options.Options() + o.profile = profile + o.binary = binary + self._driver = firefox.webdriver.WebDriver(options=o) + return self._driver + + def __exit__(self, exc_type, exc_value, exc_tb): + self._driver.quit() diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d069d14 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "grattoir" +version = "0.1.0" +license = "AGPL-3.0-or-later" +description = "A selenium webdriver using Tor IPs" +authors = ["Michaeƫl Malter "] +readme = "README.md" +packages = [{include = "grattoir"}] + +[tool.poetry.dependencies] +python = "^3.11.9" +selenium = "^4.23.1" +fake-useragent = "^1.5.1" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"