💄 Made a pretty ui

This commit is contained in:
2021-04-06 15:18:40 +03:00
parent cf7797419c
commit 5bf8fd6543
3 changed files with 50 additions and 16 deletions

29
main.py
View File

@@ -1,18 +1,22 @@
import configparser import configparser
import ast import ast
import sys
from time import sleep from time import sleep
from rich import print#, inspect from rich import print#, inspect
from rich.console import Console from rich.console import Console
from utils.authenticate import authenticate from utils.authenticate import authenticate
from utils.detect import detect from utils.detect import detect
from utils.savePhoto import save_photo
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read('config.ini') config.read('config.ini')
terms = ast.literal_eval(config['SEARCH']['terms']) terms = ast.literal_eval(config['SEARCH']['terms'])
if config['SEARCH']['interests'] != "all":
interests = ast.literal_eval(config['SEARCH']['interests']) interests = ast.literal_eval(config['SEARCH']['interests'])
c = Console() c = Console()
c.print('[b]Dochunt[/b] starting...', style='yellow')
vk = authenticate() vk = authenticate()
queries = [] queries = []
@@ -24,7 +28,13 @@ for i in range(len(terms)):
photos_processed = 0 photos_processed = 0
photos_saved = 0 photos_saved = 0
c.rule()
c.print('Watching documents :eyes:')
c.print(f'> Documents scanned {photos_processed}')
c.print(f'> Documents saved {photos_saved}')
while True: while True:
try:
for query in queries: for query in queries:
response = vk.docs.search(q=query['string'], count=1) response = vk.docs.search(q=query['string'], count=1)
image_url = response.popitem()[1][0]['url'] # WTF not readable image_url = response.popitem()[1][0]['url'] # WTF not readable
@@ -36,10 +46,25 @@ while True:
query['last_url'] = image_url_clean query['last_url'] = image_url_clean
text = detect(image_url+query['string']) text = detect(image_url+query['string'])
if interests == "all":
if not text.isspace():
photos_saved += 1
save_photo(image_url)
else:
for interest in interests: for interest in interests:
if interest in text: if interest in text:
photos_saved += 1 photos_saved += 1
c.print('Found an interesting photo!', style="green") save_photo(image_url)
c.print(image_url)
sys.stdout.write("\033[F")
sys.stdout.write("\033[K")
sys.stdout.write("\033[F")
sys.stdout.write("\033[K")
c.print(f'> Documents scanned {photos_processed}')
c.print(f'> Documents saved {photos_saved}')
sleep(1) sleep(1)
except KeyboardInterrupt:
c.print('Goodbye!', style='blue')
sys.exit()

View File

@@ -15,5 +15,6 @@ def _2fa_handler():
def authenticate(): def authenticate():
vk_session = vk_api.VkApi(login=login, password=password, auth_handler=_2fa_handler) vk_session = vk_api.VkApi(login=login, password=password, auth_handler=_2fa_handler)
vk_session.auth() vk_session.auth()
c.print('Authentication success!', style='blue')
return vk_session.get_api() return vk_session.get_api()

8
utils/savePhoto.py Normal file
View File

@@ -0,0 +1,8 @@
from rich.console import Console
c = Console()
def save_photo(url):
f = open("output.txt", "a", encoding='utf-8')
f.write(url)
f.close()