#!/usr/bin/python3 import argparse import configparser import getpass import urllib.parse import urllib.request import os #import pwd import sys import inspect from certifi.__main__ import args """ def change_user(user): try: newuid = pwd.getpwnam(user).pw_uid os.setuid(newuid) #if user is found change environ to later resolve its home pwdentry = pwd.getpwuid(os.geteuid()) os.environ['HOME'] = pwdentry.pw_dir os.environ['LOGNAME'] = pwdentry.pw_name except KeyError as e: sys.exit(f'User {args.user} not found on the system') """ def read_config(): print(" ### debut read_config " ) config = configparser.ConfigParser() configfile = os.path.expanduser('./freemobileconfig') print(" ### debut configfile = ", configfile ) if not os.path.isfile(configfile): sys.exit(f'No config file found in {getpass.getuser()} home') config.read(configfile) if not (config.has_option('id', 'user') and config.has_option('id', 'key')): sys.exit('Invalid config file') print(" ### config === ", config) return config['id']['user'], config['id']['key'] def send_sms(msg, user=None): #if user is not None: # change_user(user) print(" #### msg = ", msg) userid, key = read_config() f = { 'user' : "15383263", 'pass' : "BaRyr28QyuGUfD", 'msg' : "coucoucoucoucouuou"} print(" #### ff = ", f) url = "https://smsapi.free-mobile.fr/sendmsg?" # on encode le tout et on crée l'url d'envoi goto = url + urllib.parse.urlencode(f) # on envoie urllib.request.urlopen(goto) """ Fonction d'envoie du sms avec free """ def mysy_send_sms(): try: f = {'user': "93222911", 'pass': "EIOF1AOecBc4LZ", 'msg': "test ligne 2"} url = "https://smsapi.free-mobile.fr/sendmsg?" # on encode le tout et on crée l'url d'envoi goto = url + urllib.parse.urlencode(f) # on envoie urllib.request.urlopen(goto) return True, "SMS Envoyé" except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno)) return False, " Impossible de recherche un article/avis" return True, "OK"