Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mantaining #368

Merged
merged 8 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 1,12 @@
# Changelog
## 3.2.9 (2024-02-10)
### Fix
- remove pandas as dependency for telegram reports
- show when config file and filter file have been saved
- better logging information
## 3.2.8 (2023-01-24)
### Fix
- removed the language check
## 3.2.7 (2023-09-30)
### Fix
- using the monkey approach until this bug is fixed https://github.com/openatx/atx-agent/pull/111
Expand Down
1 change: 1 addition & 0 deletions GramAddict/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 1,5 @@
"""Human-like Instagram bot powered by UIAutomator2"""

__version__ = "3.2.8"
__tested_ig_version__ = "263.2.0.19.104"

Expand Down
20 changes: 16 additions & 4 deletions GramAddict/core/config.py
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
import logging
import os
import sys
from datetime import datetime
from typing import Optional

import configargparse
Expand Down Expand Up @@ -51,6 52,7 @@ def __init__(self, first_run=False, **kwargs):
f"You have to specify a *.yml / *.yaml config file path (For example 'accounts/your_account_name/config.yml')! \nYou entered: {file_name}, abort."
)
sys.exit(1)
logger.warning(get_time_last_save(file_name))
with open(file_name, encoding="utf-8") as fin:
# preserve order of yaml
self.config_list = [line.strip() for line in fin]
Expand Down Expand Up @@ -150,23 152,23 @@ def _is_legacy_arg(arg):
logger.debug("Arguments used:")
if self.config:
logger.debug(f"Config used: {self.config}")
if not len(self.args) > 0:
if len(self.args) == 0:
self.parser.print_help()
exit(0)
else:
if self.first_run:
logger.debug(f"Arguments used: {' '.join(sys.argv[1:])}")
if self.config:
logger.debug(f"Config used: {self.config}")
if not len(sys.argv) > 1:
if len(sys.argv) <= 1:
self.parser.print_help()
exit(0)
if self.module:
arg_str = ""
for k, v in self.args.items():
new_key = k.replace("_", "-")
new_key = " --" new_key
arg_str = new_key " " v
new_key = f" --{new_key}"
arg_str = f"{new_key} {v}"
self.args, self.unknown_args = self.parser.parse_known_args(args=arg_str)
else:
self.args, self.unknown_args = self.parser.parse_known_args()
Expand Down Expand Up @@ -205,3 207,13 @@ def _is_legacy_arg(arg):
and not _is_legacy_arg(nitem)
):
self.enabled.append(nitem)


def get_time_last_save(file_path) -> str:
try:
absolute_file_path = os.path.abspath(file_path)
timestamp = os.path.getmtime(absolute_file_path)
last_save = datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
return f"{file_path} has been saved last time at {last_save}"
except FileNotFoundError:
return f"File {file_path} not found"
13 changes: 9 additions & 4 deletions GramAddict/core/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 14,7 @@
from colorama import Fore, Style
from langdetect import detect

from GramAddict.core.config import get_time_last_save
from GramAddict.core.device_facade import Timeout
from GramAddict.core.resources import ResourceID as resources
from GramAddict.core.utils import random_sleep
Expand Down Expand Up @@ -131,8 132,11 @@ class Filter:
def __init__(self, storage=None):
filter_path = storage.filter_path
if configs.args.disable_filters:
logger.warning("Filters are disabled!")
logger.warning(
"Filters are disabled! (The default values in the documentation have been chosen!)"
)
elif os.path.exists(filter_path) and filter_path.endswith(".yml"):
logger.warning(get_time_last_save(filter_path))
with open(filter_path, "r", encoding="utf-8") as stream:
try:
self.conditions = yaml.safe_load(stream)
Expand Down Expand Up @@ -169,9 173,10 @@ def __init__(self, storage=None):
else:
logger.info(f"{k:<35} {v}", extra={"color": f"{Fore.WHITE}"})
else:
logger.warning(
"The filters file doesn't exists in your account folder. Download it from https://github.com/GramAddict/bot/blob/08e1d7aff39ec47543fa78aadd7a2f034b9ae34d/config-examples/filters.yml and place it in your account folder!"
)
if not args.disable_filters:
logger.warning(
f"The filters file doesn't exists in your account folder (can't find {filter_path}). Download it from https://github.com/GramAddict/bot/blob/08e1d7aff39ec47543fa78aadd7a2f034b9ae34d/config-examples/filters.yml and place it in your account folder!"
)

def is_num_likers_in_range(self, likes_on_post: str) -> bool:
if self.conditions is not None and likes_on_post is not None:
Expand Down
24 changes: 18 additions & 6 deletions GramAddict/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 204,26 @@ def head_up_notifications(enabled: bool = False):
"""
Enable or disable head-up-notifications
"""
cmd: str = f"adb{'' if configs.device_id is None else ' -s ' configs.device_id} shell settings put global heads_up_notifications_enabled {0 if not enabled else 1}"
cmd: str = (
f"adb{'' if configs.device_id is None else ' -s ' configs.device_id} shell settings put global heads_up_notifications_enabled {0 if not enabled else 1}"
)
return subprocess.run(cmd, stdout=PIPE, stderr=PIPE, shell=True, encoding="utf8")


def check_screen_timeout():
MIN_TIMEOUT = 5 * 6_000
cmd: str = f"adb{'' if configs.device_id is None else f' -s {configs.device_id}'} shell settings get system screen_off_timeout"
cmd: str = (
f"adb{'' if configs.device_id is None else f' -s {configs.device_id}'} shell settings get system screen_off_timeout"
)
resp = subprocess.run(cmd, stdout=PIPE, stderr=PIPE, shell=True, encoding="utf8")
try:
if int(resp.stdout.lstrip()) < MIN_TIMEOUT:
logger.info(
f"Setting timeout of the screen to {MIN_TIMEOUT/6_000:.0f} minutes."
)
cmd: str = f"adb{'' if configs.device_id is None else f' -s {configs.device_id}'} shell settings put system screen_off_timeout {MIN_TIMEOUT}"
cmd: str = (
f"adb{'' if configs.device_id is None else f' -s {configs.device_id}'} shell settings put system screen_off_timeout {MIN_TIMEOUT}"
)

subprocess.run(cmd, stdout=PIPE, stderr=PIPE, shell=True, encoding="utf8")
else:
Expand Down Expand Up @@ -270,13 276,17 @@ def call_ig():
random_sleep()
logger.debug("Setting FastInputIME as default keyboard.")
device.deviceV2.set_fastinput_ime(True)
cmd: str = f"adb{'' if configs.device_id is None else ' -s ' configs.device_id} shell settings get secure default_input_method"
cmd: str = (
f"adb{'' if configs.device_id is None else ' -s ' configs.device_id} shell settings get secure default_input_method"
)
cmd_res = subprocess.run(cmd, stdout=PIPE, stderr=PIPE, shell=True, encoding="utf8")
if cmd_res.stdout.replace(nl, "") != FastInputIME:
logger.warning(
f"FastInputIME is not the default keyboard! Default is: {cmd_res.stdout.replace(nl, '')}. Changing it via adb.."
)
cmd: str = f"adb{'' if configs.device_id is None else ' -s ' configs.device_id} shell ime set {FastInputIME}"
cmd: str = (
f"adb{'' if configs.device_id is None else ' -s ' configs.device_id} shell ime set {FastInputIME}"
)
cmd_res = subprocess.run(
cmd, stdout=PIPE, stderr=PIPE, shell=True, encoding="utf8"
)
Expand Down Expand Up @@ -418,7 428,9 @@ def print_telegram_reports(
def kill_atx_agent(device):
_restore_keyboard(device)
logger.info("Kill atx agent.")
cmd: str = f"adb{'' if configs.device_id is None else ' -s ' configs.device_id} shell pkill atx-agent"
cmd: str = (
f"adb{'' if configs.device_id is None else ' -s ' configs.device_id} shell pkill atx-agent"
)
subprocess.run(cmd, stdout=PIPE, stderr=PIPE, shell=True, encoding="utf8")


Expand Down
2 changes: 1 addition & 1 deletion GramAddict/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 1383,7 @@ def _isFollowing(self, container):
resourceId=ResourceID.BUTTON,
classNameMatches=ClassName.BUTTON_OR_TEXTVIEW_REGEX,
)
if type(text) != str:
if not isinstance(text, str):
text = text.get_text() if text.exists() else ""
return text in ["Following", "Requested"]

Expand Down
Loading
Loading