Example #1
0
    def get_articleOfSub(id_sub):
        """[summary]

        Args:
            id_sub (int): l'id unique d'un abonnement

        Returns:
            json: le(s) article(s) de l'abonnement
        """
        logger = setupLogger(__name__, "/var/www/sio/app/logs/cfast-ath.log")
        src = "/var/www/sio/app/json/articles.json"
        data = {}

        try:
            with open(src, encoding="utf-8") as file:
                articles = list(json.load(file))
        except FileNotFoundError:
            articles = ""
            logger.error(
                "Le fichier json '%s' est introuvable ou n'existe pas." % src)

        index = 0
        for article in articles:
            if id_sub == article["article"]["id_sub"]:
                data["%d" % index] = article
                index += 1

        if data == "":
            logger.error(
                "l'abonnement n°%d ne contient pas d'article ou n'existe pas."
                % id_sub)

        return data
Example #2
0
    def get_sub(id_sub):
        """[summary]

        Args:
            id_sub (int): l'id unique d'un abonnement

        Returns:
            json: le détail de l'abonnement(s)
        """
        logger = setupLogger(__name__, "/var/www/sio/app/logs/cfast-ath.log")
        src = "/var/www/sio/app/json/service.json"
        data = {}

        subs = M_CF_Subscription.get_allSubs()
        index = 0
        for sub in subs:
            items = sub["items"]
            for item in items:
                if id_sub == item["id"]:
                    data = item
                    index += 1

        if data == "":
            logger.error("l'abonnement n°%d n'existe pas." % id_sub)

        return data
Example #3
0
    def get_allSubs():
        """[summary]

        Returns:
            json: tout les abonnements
        """
        logger = setupLogger(__name__, "/var/www/sio/app/logs/cfast-ath.log")
        src = "/var/www/sio/app/json/subscriptions.json"
        try:
            with open(src, encoding="utf-8") as file:
                data = list(json.load(file))
        except FileNotFoundError:
            data = ""
            logger.error(
                "Le fichier json '%s' est introuvable ou n'existe pas." % src)
        return data
Example #4
0
    def get_subsFromService(id_service):
        """[summary]

        Args:
            id_service (int): l'id unique d'un service cfast

        Returns:
            json: le(s) abonnement(s) du service
        """
        logger = setupLogger(__name__, "/var/www/sio/app/logs/cfast-ath.log")
        src = "/var/www/sio/app/json/service.json"
        data = []

        all_subs = M_CF_Subscription.get_allSubs()
        index = 0
        for subs in all_subs:
            if id_service == subs["serviceId"]:
                data.append(subs)

        if data == "":
            logger.error("Aucuns abonnements pour le service n°%d" %
                         id_service)

        return data
Example #5
0
from tqdm import tqdm
from time import sleep
import csv
import os
import concurrent.futures
import time
import logging
#------------------#
from requests.structures import CaseInsensitiveDict
from getToken import getTokenCfast, getTokenSubs  #script de recuperation du token d'authorisation
from datetime import datetime
from tools import setupLogger
#------------------#
#* ------ /Import ------- *#

logger = setupLogger(__name__, "logs/importSite.log")
"""[summary]
Import d'un site dans cfast
    @data : json contenant les données du site
"""


def importSite(data):
    token = getTokenCfast
    insertSite = "https://v2.cfast.fr/api/cfast/site"
    headers = CaseInsensitiveDict()
    headers = {'Content-type': 'application/json;charset=utf-8'}
    headers["Authorization"] = "Bearer %s" % token
    data = {}
    # res_insertSite = requests.post(insertSite, json.dumps(data), headers=headers)
    if (res_insertSite.status_code == 204):
Example #6
0
#! /usr/bin/python3
import logging
import requests
import json
from requests.structures import CaseInsensitiveDict
from tools import setupLogger

logger = setupLogger(__name__, "logs/getToken.log")

def getTokenSubs():
    token = ""

    #Script de recuperation du token    
    url = "https://v2.cfast.fr/auth/connect/token"
    headers = CaseInsensitiveDict()
    headers["Content-Type"] = "application/x-www-form-urlencoded"
    headers["Authorization"] = "Basic Z3RvLmNsaWVudDpNaUJxVFZRVnYxMlV2cVdDQVFmQ1l6dVZ5OG1JbXJUaDhvam1ZTGdERkJ2c0NVV2xtV0dSeTYtY3ZRdGRfcjlpdXFUMXk1X3JiVy1YcWViQ0IxeE5YSzR5QTRyYWhsVHFDOXhCaWdHemxiam5HMm5uZXllOGRiTlNiQS15RWFGdlFzdGFXRFd5NA=="
    data = "grant_type=password&username=gto.api&password=bXOp*cE;uo1R&scope=openid%20identity%20subs"
    resp = requests.post(url, headers=headers, data=data)

    if (resp.status_code == 200):
        respObject = resp.json()
        token = respObject["access_token"]
        logger.debug("Nouveau token subs généré.")
    else: 
        token = "error"
        logger.error("Status: %s - Message: %s" % (resp.status_code, resp.text))

    return token

def getTokenCfast():
Example #7
0
from datetime import datetime
from tools import setupLogger, sendRapport
from tqdm import tqdm
from time import sleep
#------------------#
#import des models
from M_ATH_Contrat import *
from M_CF_Contract import *
from M_CF_Service import *
from M_CF_Subscription import *
from Service import *
from Sub import *
from Contrat import *
#* ------ /Import ------- *#

logger = setupLogger(__name__, "logs/cfast-ath.log")

start = time.perf_counter()

EMAIL_ADRESS = "*****@*****.**"
EMAIL_PASS = "******"


def main():

    #Création des tokens:
    # tokenCfast = getTokenCfast()
    # tokenSubs = getTokenSubs()

    #Déclaration des objets
    cf_contrat = M_CF_Contract(tokenCfast)
Example #8
0
#------------------#
from email.message import EmailMessage
from requests.structures import CaseInsensitiveDict
from getToken import getTokenCfast, getTokenSubs  #script de recuperation du token d'authorisation
from datetime import datetime
from tools import setupLogger
#------------------#
#import des models
from M_CF_Service import *
from M_CF_Subscription import *
from Service import *
from Sub import *
#* ------ /Import ------- *#
#* ------ Méthodes ------- *#

logger = setupLogger(__name__, "logs/serviceSansSub.log")
"""[summary]
Récupère la reférence interne depuis l'id cfast
    @id cfast du client
"""


def getInternalRef(id):
    token = getTokenCfast()
    headers = CaseInsensitiveDict()
    headers["Authorization"] = "Bearer %s" % token
    request = "https://v2.cfast.fr/api/cfast/company/%s" % id
    res = requests.get(request, headers=headers)
    comp_detail = res.json()
    internalRef = comp_detail["internalCompanyReference"]
    return internalRef
Example #9
0
# import pymysql  
import pymysql
import pymysql.cursors
import sys
from tools import setupLogger

logger = setupLogger(__name__, "/var/www/sio/app/logs/dbConnect.log")

def connect():
    # try:
    conn = pymysql.connect(host='localhost',
                    port= 3306,
                    user='******',
                    password='******',
                    database='CFAST_ATH',
                    cursorclass=pymysql.cursors.DictCursor)

    # except pymysql.err.OperationalError:
    #     logger.error("A MSSQLDriverException has been caught. - Vérifier les infos de connexion dans dbConnect.py")
    #     sys.exit()

    logger.info("Connexion à la base de donnée réussie.")
    return conn

connect()