Skip to content
Snippets Groups Projects
Commit a5c96381 authored by Aaron Gogniat's avatar Aaron Gogniat
Browse files

project done, deleted authentificaction keys, readme completed

parent bcc19a7e
Branches main
No related tags found
No related merge requests found
.venv\Scripts\activate
1) entrer les tokens d'authenfication des différentes APIs (lines 261-264, 282, 300-301)
2) ouvrir l'environnement : .venv\Scripts\activate
3) avoir la base de données Odoo et Deputy ouverts
4) lancer le code python : python .\app.py
5) lancer le serveur flask : http://127.0.0.1:5000
python .\app.py
have odoo and (deputy open) and run the flask server http://127.0.0.1:5000
#everything in comment is things i tried throughout this project
import xmlrpc.client
#everything in comment is things I've tried throughout this project
import xmlrpc.client #Odoo
import requests
from flask import Flask, render_template, request #, send_file
import os
#import os
#import pandas
#import xlrd
#from openpyxl import load_workbook
from twilio.rest import Client
from twilio.rest import Client #Twilio
#from werkzeug.utils import secure_filename
import time
......@@ -47,11 +47,8 @@ def get_all_employee_from_odoo():
######################### Get employees' info from Deputy ######################################################################################################################################
def get_all_employee_from_deputy():
url = "https://9aad9b25014108.eu.deputy.com/api/management/v2/employees?fieldMask=id,firstName,lastName,displayName,contact"
headers = {
"accept": "application/json",
"authorization": "Bearer 16244f0f5eed31873660c2dccf3fa71d"
}
url = f"{urlbase_deputy}/api/management/v2/employees?fieldMask=id,firstName,lastName,displayName,contact"
response = requests.get(url, headers=headers)
# Check if the request was successful
......@@ -165,7 +162,7 @@ def employee_list_to_delete(odoo_employees, deputy_employees) :
#################################### Add or modifiy employees to Deputy #########################################################################################################################
def send_new_employees_to_deputy(employees_to_add):
url = "https://9aad9b25014108.eu.deputy.com/api/management/v2/employees"
url = f"{urlbase_deputy}/api/management/v2/employees"
# Add new employees
for employee in employees_to_add:
......@@ -179,18 +176,14 @@ def send_new_employees_to_deputy(employees_to_add):
"id": "1" # Needed to be able to send
}
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": "Bearer 16244f0f5eed31873660c2dccf3fa71d"
}
headers_send = headers
headers_send["content-type"] = "application/json"
response = requests.post(url, json=payload, headers=headers)
response = requests.post(url, json=payload, headers=headers_send)
print(response.text)
#print("DATA : ", data)
print ('JSON DATA : ', response)
#print ('JSON DATA : ', response)
if response.status_code == 200:
print(f"New employee {employee['firstName']} {employee['lastName']} added successfully to Deputy")
else:
......@@ -205,12 +198,8 @@ def update_modified_employees_on_deputy(employees_to_update):
#print(employee)
#print(id_employee)
url = f"https://9aad9b25014108.eu.deputy.com/api/management/v2/employees/{id_employee}"
url = f"{urlbase_deputy}/api/management/v2/employees/{id_employee}"
#print(url)
headers = {
"accept": "application/json",
"authorization": "Bearer 16244f0f5eed31873660c2dccf3fa71d"
}
data = {
"firstName": employee["firstName"],
......@@ -222,7 +211,7 @@ def update_modified_employees_on_deputy(employees_to_update):
}
response = requests.patch(url, headers=headers, json=data)
print ('JSON DATA : ', response)
#print ('JSON DATA : ', response)
if response.status_code == 200:
print(f"Employee {employee['firstName']} {employee['lastName']} updated successfully in Deputy")
else:
......@@ -236,27 +225,19 @@ def delete_employees_on_deputy(employees_to_delete) :
#print(employee)
#print(id_employee)
url = f"https://9aad9b25014108.eu.deputy.com/api/v1/supervise/employee/{id_employee}/terminate" #"https://9aad9b25014108.eu.deputy.com/api/v1/supervise/employee/{id_employee}/delete"
url = f"{urlbase_deputy}/api/v1/supervise/employee/{id_employee}/terminate" #"{urlbase_deputy}/api/v1/supervise/employee/{id_employee}/delete"
#=> does not work ! can only terminate them which archive them which will still delete them from the 'employee' deputy database
headers = {
"accept": "application/json",
"authorization": "Bearer 16244f0f5eed31873660c2dccf3fa71d"
}
response = requests.post(url, headers=headers)
print ('JSON DATA : ', response.text)
#print ('JSON DATA : ', response.text)
if response.status_code == 200:
print(f"Employee {employee['firstName']} {employee['lastName']} archived successfully in Deputy")
else:
print(f"Failed to archived employee {employee['firstName']} {employee['lastName']} in Deputy")
##################################### Send link to the odoo employees with Twilio ############################################################################################################
def send_the_link_to_employee_odoo (odoo_employees,file) :
# Twilio Authentication
account_sid = 'AC893c48ec4d8b41bf6bad7f1e5ae9215f'
auth_token = 'c22795efae82c8b04ea2634851aa76a6'
def send_the_link_to_employee_odoo (odoo_employees,link) :
client = Client(account_sid, auth_token)
# Send a message to each employee
for employee in odoo_employees:
......@@ -264,7 +245,7 @@ def send_the_link_to_employee_odoo (odoo_employees,file) :
work_phone = employee['workPhone']
message = client.messages.create(
from_='whatsapp:+14155238886',
body=f'Voici le planning mis à jour. Bonne journée {file}',
body=f'Voici le planning mis à jour. Bonne journée {link}',
to=f'whatsapp:{work_phone}'
)
time.sleep(1.1) #sleep 1 second because Twilio has a 1rps rate, 1.1 second just to be sure
......@@ -275,49 +256,54 @@ def send_the_link_to_employee_odoo (odoo_employees,file) :
# No main function because of flask
######################### Authenticate with Odoo API ###########################################################################################
# Connection Configuration
url = 'http://localhost:8069/'
db = 'SIE'
username = 'orgogniat@gmail.com'
password = '789321Odooy:D'
# Connection Configuration : to change with your own information
# in order to link your Odoo database
url_odoo = 'http://localhost:8069/'# To change if it is not on localhost
db = '' # Enter your database name
username = '' # Enter your username/adresse email
password = '' # Enter your password
# Connect to the Odoo API
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url_odoo))
# Authenticate with the Odoo API
uid = common.authenticate(db, username, password, {})
if uid:
print('Authenticated with Odoo API')
else:
print('Authentication failed')
if uid:
# Connected and authenticated successfully
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url_odoo))
print('Authenticated with Odoo API')
else:
print('Authentication failed. Stopping the app. Goodbye.')
print('Authentication failed')
exit(1)
########################## Authenticate with Deputy API ######################################################################################
# Connection Configuration
url = "https://9aad9b25014108.eu.deputy.com/api/v1/my/setup"
urlbase_deputy = "" # Enter your URL with the identification, it should look like this https://{install}.{geo}.deputy.com
url_deputy = f"{urlbase_deputy}/api/v1/me"
# print(url_deputy)
headers = {
"accept": "application/json",
"authorization": "Bearer 16244f0f5eed31873660c2dccf3fa71d"
"authorization": "Bearer " # Enter the Access Token after "Bearer", for example "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxx"
}
response = requests.get(url, headers=headers)
response = requests.get(url_deputy, headers=headers)
if response.status_code == 200:
print('Connected to Deputy API successfully')
else:
print('Failed to connect to Deputy API')
exit(1)
############################ Authenticate with Twilio API ##########################################################################################
# Twilio Authentication
account_sid = '' # Enter your Account SID
auth_token = '' # Enter your Auth Token
########################### THE EXECUTION LINES ################################################################################################
# Retrieve employees from Odoo and Deputy
odoo_employees = get_all_employee_from_odoo()
print ("ODOO EMPLOYEES :", odoo_employees)
deputy_employees = get_all_employee_from_deputy()
print ("DEPUTY EMPLOYEES :", deputy_employees)
......@@ -344,12 +330,13 @@ print ("DELETED EMPLOYEES :", delete_employees)
if delete_employees :
# Update Deputy with deleted employees
delete_employees_on_deputy(delete_employees)
############################### FLASK #############################################################################################################
############################### FLASK #############################################################################################################
app = Flask(__name__)
@app.route('/')
# Waits for the link to be sent
# Wait for the link to be sent
def index():
return render_template('homepage.html')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment