jaklis/gchange-profile.py

56 lines
1.7 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import argparse, sys, os
from os.path import join, dirname
from shutil import copyfile
from dotenv import load_dotenv
2020-11-29 23:33:50 +01:00
from lib.gchange import ReadLikes, SendLikes, UnLikes
# Get variables environment
if not os.path.isfile('.env'):
copyfile(".env.template", ".env")
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
dunikey = os.getenv('DUNIKEY')
pod = os.getenv('POD')
if not dunikey or not pod:
sys.stderr.write("Please fill the path of your private key (PubSec), and a Cesium ES address in .env file\n")
sys.exit(1)
# Parse arguments
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
2020-11-29 23:33:50 +01:00
# readLike_cmd = subparsers.add_parser('readlike', help="Lire les likes d'un profile")
like_cmd = subparsers.add_parser('like', help="Voir les likes d'un profile / Liker un profile (option -s NOTE")
unlike_cmd = subparsers.add_parser('unlike', help="Supprimer un like")
2020-11-29 23:33:50 +01:00
if len(sys.argv) <= 1 or not sys.argv[1] in ('like','unlike'):
sys.stderr.write("Veuillez indiquer une commande valide:\n\n")
parser.print_help()
sys.exit(1)
2020-11-29 23:33:50 +01:00
# readLike_cmd.add_argument('-p', '--profile', help="Profile cible")
like_cmd.add_argument('-p', '--profile', help="Profile cible")
like_cmd.add_argument('-s', '--stars', type=int, help="Nombre d'étoile")
2020-11-29 23:33:50 +01:00
unlike_cmd.add_argument('-p', '--profile', help="Profile à déliker")
args = parser.parse_args()
# Build gchange class
2020-11-29 23:33:50 +01:00
if sys.argv[1] == "like":
2020-11-29 23:42:57 +01:00
if args.stars or args.stars == 0:
2020-11-29 23:33:50 +01:00
gchange = SendLikes(dunikey, pod)
2020-11-30 00:43:21 +01:00
gchange.like(args.stars, args.profile)
2020-11-29 23:33:50 +01:00
else:
gchange = ReadLikes(dunikey, pod)
gchange.readLikes(args.profile)
elif sys.argv[1] == "unlike":
gchange = UnLikes(dunikey, pod)
gchange.unLike(args.profile)