Skip to content

Commit

Permalink
Release v1.0.2 (#45)
Browse files Browse the repository at this point in the history
* No one is maintaining these - removing
- These likely need re-written from scratch anyway
- removing resources we don't use like patreon or the insomniac logo

* No one is maintaining these - removing (#33)

- These likely need re-written from scratch anyway
- removing resources we don't use like patreon or the insomniac logo

* Feature analytics (#31)

* increment version

* fixing bug with interact argument

* ignoring all .pdf files

* Adding tool to generate PDF reports with statistics using matplotlib

* blackening

Co-authored-by: narkopolo <[email protected]>

* Adding missing dependency (#37)

* No one is maintaining these - removing
- These likely need re-written from scratch anyway
- removing resources we don't use like patreon or the insomniac logo

* adding matplotlib dependency

* Use python logging module (#36)

* Use python logging module

- add log.py: used to configure
python logging module

There are two log handlers: one colored
for the console and one with raw data for the
crash report. This way we will be able to make
the console be less cluttered while still have debug
information when a crash happens.

* Change plugin loading log level to INFO

* Remove unused log constants (#41)

* Remove pipenv because they can't figure out how to support python version ranges pypa/pipenv#1050 (#44)

* No one is maintaining these - removing
- These likely need re-written from scratch anyway
- removing resources we don't use like patreon or the insomniac logo

* removing pipenv

* removing extra res folder - updating version

Co-authored-by: narkopolo <[email protected]>
Co-authored-by: Arthur Silva <[email protected]>
  • Loading branch information
3 people authored Nov 14, 2020
1 parent 1fec470 commit e1fac76
Show file tree
Hide file tree
Showing 23 changed files with 475 additions and 614 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ filter.json
whitelist.txt
Pipfile.lock
*.pdf
.venv
104 changes: 38 additions & 66 deletions GramAddict/__init__.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
import argparse
from time import sleep
import colorama
import logging
import sys
from datetime import datetime
from time import sleep

# from http.client import HTTPException
# from socket import timeout
from colorama import Fore, Style

from GramAddict.core.device_facade import create_device
from GramAddict.core.log import configure_logger
from GramAddict.core.navigation import switch_to_english
from GramAddict.core.persistent_list import PersistentList
from GramAddict.core.plugin_loader import PluginLoader
from GramAddict.core.report import print_full_report
from GramAddict.core.session_state import (
SessionState,
SessionStateEncoder,
)
from GramAddict.core.session_state import SessionState, SessionStateEncoder
from GramAddict.core.storage import Storage
from datetime import datetime
from GramAddict.core.utils import (
COLOR_HEADER,
COLOR_WARNING,
COLOR_FAIL,
COLOR_ENDC,
get_version,
check_adb_connection,
close_instagram,
get_instagram_version,
get_value,
get_version,
open_instagram,
close_instagram,
screen_sleep,
save_crash,
get_value,
print_timeless,
print,
screen_sleep,
)
from GramAddict.core.views import TabBarView


# Script Initialization
print_timeless(COLOR_HEADER + "GramAddict " + get_version() + COLOR_ENDC)
colorama.init()
# Logging initialization
configure_logger()
logger = logging.getLogger(__name__)
logger.info(
"GramAddict " + get_version(), extra={"color": f"{Style.BRIGHT}{Fore.MAGENTA}"}
)

# Global Variables
device_id = None
Expand Down Expand Up @@ -72,7 +65,7 @@ def load_plugins():
if arg.get("operation", False):
actions[arg["arg"]] = plugin
except Exception as e:
print_timeless(
logger.error(
f"Error while importing arguments of plugin {plugin.__class__.__name__}. Error: Missing key from arguments dictionary - {e}"
)
return actions
Expand All @@ -86,11 +79,8 @@ def get_args():
args, unknown_args = parser.parse_known_args()

if unknown_args:
print(
COLOR_FAIL
+ "Unknown arguments: "
+ ", ".join(str(arg) for arg in unknown_args)
+ COLOR_ENDC
logger.error(
"Unknown arguments: " + ", ".join(str(arg) for arg in unknown_args)
)
parser.print_help()
return False
Expand All @@ -110,8 +100,8 @@ def run():
for k in loaded:
if dargs[k.replace("-", "_")[2:]] != None:
if k == "--interact":
print_timeless(
f'{COLOR_WARNING}Warning: Using legacy argument "--interact". Please switch to new arguments as this will be deprecated in the near future.{COLOR_ENDC}'
logger.warn(
'Using legacy argument "--interact". Please switch to new arguments as this will be deprecated in the near future.'
)
if "#" in args.interact[0]:
enabled.append("--hashtag-likers")
Expand All @@ -124,18 +114,11 @@ def run():
enabled = list(dict.fromkeys(enabled))

if len(enabled) < 1:
print_timeless(
COLOR_FAIL
+ "You have to specify one of the actions: "
+ ", ".join(loaded)
+ COLOR_ENDC
)
logger.error("You have to specify one of the actions: " + ", ".join(loaded))
return
if len(enabled) > 1:
print_timeless(
COLOR_FAIL
+ "Running GramAddict with two or more actions is not supported yet."
+ COLOR_ENDC
logger.error(
"Running GramAddict with two or more actions is not supported yet."
)
return

Expand All @@ -146,18 +129,14 @@ def run():
device_id = args.device
if not check_adb_connection(is_device_id_provided=(device_id is not None)):
return

print("Instagram version: " + get_instagram_version())
logger.info("Instagram version: " + get_instagram_version())
device = create_device(device_id)
if device is None:
return
while True:
print_timeless(
COLOR_WARNING
+ "\n-------- START: "
+ str(session_state.startTime)
+ " --------"
+ COLOR_ENDC
logger.info(
"-------- START: " + str(session_state.startTime) + " --------",
extra={"color": f"{Style.BRIGHT}{Fore.YELLOW}"},
)

if args.screen_sleep:
Expand All @@ -172,7 +151,7 @@ def run():
session_state.my_following_count,
) = profileView.getProfileInfo()
except Exception as e:
print(f"Exception: {e}")
logger.error(f"Exception: {e}")
save_crash(device)
switch_to_english(device)
# Try again on the correct language
Expand All @@ -188,17 +167,14 @@ def run():
or not session_state.my_followers_count
or not session_state.my_following_count
):
print(COLOR_FAIL + "Could not get profile info" + COLOR_ENDC)
logger.critical("Could not get profile info")
exit(1)

report_string = ""
report_string += "Hello, @" + session_state.my_username + "! "
report_string += (
"You have " + str(session_state.my_followers_count) + " followers"
)
report_string += " and " + str(session_state.my_following_count) + " followings"
report_string += " so far."
print(report_string)
username = session_state.my_username
followers = session_state.my_followers_count
following = session_state.my_following_count
report_string = f"Hello, @{username}! You have {followers} followers and {following} followings so far."
logger.info(report_string, extra={"color": f"{Style.BRIGHT}"})

storage = Storage(session_state.my_username)

Expand All @@ -210,17 +186,13 @@ def run():
if args.screen_sleep:
screen_sleep(device_id, "off") # Turn off the device screen

print_timeless(
COLOR_WARNING
+ "-------- FINISH: "
+ str(session_state.finishTime)
+ " --------"
+ COLOR_ENDC
logger.info(
"-------- FINISH: " + str(session_state.finishTime) + " --------",
extra={"color": f"{Style.BRIGHT}{Fore.YELLOW}"},
)

if args.repeat:
print_full_report(sessions)
print_timeless("")
repeat = get_value(args.repeat, "Sleep for {} minutes", 180)
try:
sleep(60 * repeat)
Expand Down
32 changes: 12 additions & 20 deletions GramAddict/core/decorators.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import logging
import sys
import traceback
from datetime import datetime
from http.client import HTTPException
from socket import timeout
from datetime import datetime
import sys

from GramAddict.core.device_facade import DeviceFacade
from GramAddict.core.report import print_full_report
from GramAddict.core.utils import (
COLOR_WARNING,
COLOR_FAIL,
COLOR_ENDC,
open_instagram,
close_instagram,
open_instagram,
random_sleep,
save_crash,
print_timeless,
print,
)

from GramAddict.core.views import LanguageNotEnglishException, TabBarView

logger = logging.getLogger(__name__)


def run_safely(device, device_id, sessions, session_state):
def actual_decorator(func):
Expand All @@ -29,28 +26,23 @@ def wrapper(*args, **kwargs):
func(*args, **kwargs)
except KeyboardInterrupt:
close_instagram(device_id)
print_timeless(
COLOR_WARNING
+ "-------- FINISH: "
+ str(datetime.now().time())
+ " --------"
+ COLOR_ENDC
)
logger.warn(f"-------- FINISH: {datetime.now().time()} --------")
print_full_report(sessions)
sessions.persist(directory=session_state.my_username)
sys.exit(0)
except (DeviceFacade.JsonRpcError, IndexError, HTTPException, timeout):
print(COLOR_FAIL + traceback.format_exc() + COLOR_ENDC)
logger.error(traceback.format_exc())
save_crash(device)
print("No idea what it was. Let's try again.")
logger.info("No idea what it was. Let's try again.")
# Hack for the case when IGTV was accidentally opened
close_instagram(device_id)
random_sleep()
open_instagram(device_id)
TabBarView(device).navigateToProfile()
except LanguageNotEnglishException:
print_timeless("")
print("Language was changed. We'll have to start from the beginning.")
logger.info(
"Language was changed. We'll have to start from the beginning."
)
TabBarView(device).navigateToProfile()
except Exception as e:
save_crash(device)
Expand Down
15 changes: 7 additions & 8 deletions GramAddict/core/device_facade.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import logging
from enum import Enum, unique
import uiautomator2
from GramAddict.core.utils import (
COLOR_FAIL,
COLOR_ENDC,
print,
)
from random import uniform

import uiautomator2

logger = logging.getLogger(__name__)

# How long we're waiting until UI element appears (loading content + animation)
UI_TIMEOUT_LONG = 5
UI_TIMEOUT_SHORT = 1


def create_device(device_id):
print("Using uiautomator v2")
logger.debug("Using uiautomator v2")
try:
return DeviceFacade(device_id)
except ImportError as e:
print(COLOR_FAIL + str(e) + COLOR_ENDC)
logger.error(str(e))
return None


Expand Down
Loading

0 comments on commit e1fac76

Please sign in to comment.