def __init__(self, sharepoint_base_url, username, password): self.username = username self.password = password self.sharepoint_base_url = sharepoint_base_url self.authcookie = Office365(sharepoint_base_url, username=username, password=password).GetCookies()
def call_for_content(): APP_ID = '5995b22a-e094-4d5b-8523-edd7bb089d89' APP_PASSWORD = '******' CHANNEL_ID = 'msteams' BOT_ID = '5995b22a-e094-4d5b-8523-edd7bb089d89' authcookie = Office365('https://thespurgroup.sharepoint.com', username='******', password='******').GetCookies() site = Site('https://thespurgroup.sharepoint.com/sites/bot_project_test/', version=Version.v2016, authcookie=authcookie) folder_path = 'Shared Documents/Lono2docs/' teams_tracker = folder.get_file('testing.csv') source_stream = io.BytesIO(teams_tracker) df = pd.read_csv(source_stream).drop(columns=['Unnamed: 0']) for index, row in df.iterrows(): SERVICE_URL = row.serviceURL recipient_id = row.recipientID TENANT_ID = row.tenantID NAME = row.Name to = ChannelAccount(id=recipient_id) bot_channel = ChannelAccount(id=CHANNEL_ID) MicrosoftAppCredentials.trust_service_url(SERVICE_URL) credentials = MicrosoftAppCredentials(APP_ID, APP_PASSWORD) conn_client = ConnectorClient(credentials, SERVICE_URL) message_activity = MessageFactory.text(f"Hello {NAME}, are you going to submit an article for this month's newsletter?"); conversation_params = ConversationParameters(members=[to], channel_data={ 'tenant': { 'id': TENANT_ID } }) conversation = conn_client.conversations.create_conversation(conversation_params) conn_client.conversations.send_to_conversation(conversation.id, message_activity)
def main(req: func.HttpRequest) -> func.HttpResponse: # Configuration Sanity Check o365HostUri = os.environ['O365HostUri'] o365UserName = os.environ['O365UserName'] o365UserPassword = os.environ['O365UserPassword'] o365SiteUri = os.environ['O365SiteUri'] o365ListName = os.environ['O365ListName'] validationError = False if not o365HostUri: validationError = True logging.error('O365HostUri configuration missing.') if not o365UserName: validationError = True logging.error('O365UserName configuration missing.') if not o365UserPassword: validationError = True logging.error('O365UserPassword configuration missing.') if not o365SiteUri: validationError = True logging.error('O365SiteUri configuration missing.') if not o365ListName: validationError = True logging.error('O365ListName configuration missing.') if validationError: return func.HttpResponse("Invalid configuration.", status_code=400) authcookie = Office365(o365HostUri, username=o365UserName, password=o365UserPassword).GetCookies() site = Site(o365SiteUri, version=Version.v365, authcookie=authcookie) sp_list = site.List(o365ListName) data = sp_list.GetListItems('All Items') logging.info(data) return func.HttpResponse(json.dumps(data), status_code=200, mimetype='application/json')
def login(self): authcookie = Office365( StringUtils.StringUtils.website, username=StringUtils.StringUtils.email, password=StringUtils.StringUtils.passwort).GetCookies() self.__site = Site(StringUtils.StringUtils.websiteAPI, version=Version.v365, authcookie=authcookie)
def run(): wb = load_workbook(filename='data.xlsx', read_only=True) ws = wb['Raw Data'] data = ws.values columns = next(data)[1:] data = list(data) idx = [r[0] for r in data] data = (islice(r, 1, None) for r in data) df = pd.DataFrame(data, index=idx, columns=columns) # print(df.loc[[1130359]]) authcookie = Office365('https://purdue0.sharepoint.com', username='', password='').GetCookies() site = Site('https://purdue0.sharepoint.com/sites/HRIS', version=Version.o365, authcookie=authcookie) test_list = site.List('ELT-Test') # while True: # list_items = test_list.GetListItems('All Items', fields=['ID'], row_limit=500) # if len(list_items) == 0: # break # id_list = [x['ID'] for x in list_items] # log.info('Starting deletion of {} records'.format(str(len(list_items)))) # test_list.UpdateListItems(data=id_list, kind='Delete') # log.info('Deletion complete.') # print (len(list_items)) list_items = [] try: list_items = test_list.GetListItems( 'All Items', fields=['ID', 'Employee Name'], # query={'Where': ['Or', ('Eq', 'Employee Name', 'Mark Holmes'), ('Eq', 'Employee Name', 'Patricia Prince')]}, query={'Where': [('Eq', 'Employee Name', 'Mark Holmes')]}, ) except shareplum.errors.ShareplumRequestError as err: log.error(err) if err.details and type( err.details) == requests.exceptions.HTTPError: if err.details.response.status_code in [429, 503]: # TODO: Sleep for Retry-After to prevent further throttling pass elif err.details.response.status_code in [500]: log.error(err.details.response.request.body) log.error(err.details.response.content) for list_item in list_items: log.info(list_item)
def o365_login(tenant, username, password, site_o365, shared_folder): authcookie = Office365( tenant, username=base64.b64decode(username).decode('utf-8'), password=base64.b64decode(password).decode('utf-8')).GetCookies() site = Site(site_o365, version=Version.v365, authcookie=authcookie) folder_shared_o365 = site.Folder(shared_folder) print(time_now(), f' Login to O365 to {site_o365} is successful!') return folder_shared_o365
def connect(self): config_details = config('config.ini', 'sharepoint') auth_cookie = Office365(config_details['base_url'], username=config_details['user'], password=config_details['pass']).GetCookies() conn = Site(config_details['url'], authcookie=auth_cookie) return conn
def auth(self): self.authcookie = Office365(SHAREPOINT_URL, username=USERNAME, password=PASSWORD).GetCookies() self.site = Site(SHAREPOINT_SITE, version=Version.v365, authcookie=self.authcookie) return self.site
def download(self) -> list: dl_files = [] # parse url parsed = urlparse(self.site) scheme = 'https' if parsed.scheme == '' else parsed.scheme version = 365 if self.version == '365': sp_version = Version.v365 else: sp_version = Version.v2007 try: if sp_version == Version.v365: authcookie = Office365(f'{scheme}://{parsed.netloc}', username=self.username, password=self.password).GetCookies() else: cred = HttpNtlmAuth(self.username, self.password) except: raise Exception( f'Unable to authenticate using supplied user name and password.' ) else: self.display_info('Sucessfully authnticated') try: if sp_version == Version.v365: site = Site(self.site, version=sp_version, authcookie=authcookie) else: site = Site(self.site, version=sp_version, auth=cred) except: raise Exception(f'{self.site} is not a valid site') else: self.display_info(f'Sucessfully accessed site {self.site}') # build path to document folder doc_path = os.path.join(parsed.path, self.docs) try: folder = site.Folder(doc_path) for f in folder.files: fname = f['Name'] if fnmatch.fnmatch(fname, self.filespec): dest = os.path.join(self.savepath, fname) with open(dest, mode='wb') as file: file.write(folder.get_file(fname)) dl_files.append(dest) except: raise Exception(f'Unable to download files from {self.docs}') return dl_files
def get_data(team_slug, folder_name, file_name): authcookie = Office365('https://devpatrol.sharepoint.com', username=SP_USERNAME, password=SP_PASSWORD).GetCookies() site = Site('https://devpatrol.sharepoint.com/sites/' + team_slug, version=Version.v365, authcookie=authcookie, verify_ssl=False) folder = site.Folder('Shared Documents/' + folder_name) response = folder.get_file(file_name) return response
def setUp(self): if TEST_SETTINGS["version"] in ["2014", "2016", "2019", "365"]: version = Version.v2016 else: version = Version.v2007 authcookie = Office365(TEST_SETTINGS["server_url"], username=TEST_SETTINGS["username"], password=TEST_PASSWORD).GetCookies() self.site = Site(TEST_SETTINGS["site_url"], version=version, authcookie=authcookie)
def setUp(self): with open("test_server.json") as f: self.server = json.load(f) if self.server["version"] in ["2014", "2016", "2019", "365"]: version = Version.v2016 else: version = Version.v2007 authcookie = Office365( self.server["server_url"], username=self.server["username"], password=os.environ.get('TEST_PASSWORD')).GetCookies() self.site = Site(self.server["site_url"], version=version, authcookie=authcookie)
def sharepoint_list(Secrets): """ Connection to SharePoint API with password authentication """ username = Secrets['sharepoint']['user_name'] password = Secrets['sharepoint']['password'] web_site = Secrets['sharepoint']['web_site'] my_site = Secrets['sharepoint']['my_site'] authcookie = Office365(my_site, username=username, password=password).GetCookies() site = Site(web_site, authcookie=authcookie) result = site.List('Risk Registry').GetListItems() return result
def setUp(self): if TEST_SETTINGS["version"] in ["2014", "2016", "2019", "365"]: version = Version.v2016 else: version = Version.v2007 if TEST_SETTINGS["version"] == "365": authcookie = Office365(TEST_SETTINGS["server_url"], username=TEST_SETTINGS["username"], password=TEST_PASSWORD).GetCookies() self.site = Site(TEST_SETTINGS["site_url"], version=version, authcookie=authcookie) else: auth = HttpNtlmAuth(TEST_SETTINGS["username"], TEST_PASSWORD) self.site = Site(TEST_SETTINGS["site_url"], version=version, auth=auth) self.test_list = TEST_SETTINGS["test_list"]
from botbuilder.core import TurnContext, ActivityHandler, ConversationState, MessageFactory from botbuilder.dialogs import DialogSet, WaterfallDialog, WaterfallStepContext from botbuilder.dialogs.prompts import TextPrompt, NumberPrompt, PromptOptions, ChoicePrompt from botbuilder.dialogs.choices import Choice import requests import pymsteams from shareplum import Site from shareplum import Office365 from shareplum.site import Version sharepointUsername = "******" sharepointPassword = "******" sharepointSite = "https://azdemoclient01.sharepoint.com/sites/site0" website = "https://azdemoclient01.sharepoint.com" authcookie = Office365(website, username=sharepointUsername, password=sharepointPassword).GetCookies() site = Site(sharepointSite, version=Version.v2016, authcookie=authcookie) class BotDialog(ActivityHandler): def __init__(self, conversation: ConversationState): self.con_statea = conversation self.state_prop = self.con_statea.create_property("dialog_set") self.dialog_set = DialogSet(self.state_prop) self.dialog_set.add(TextPrompt("text_prompt")) self.dialog_set.add(NumberPrompt("number_prompt")) self.dialog_set.add(ChoicePrompt(ChoicePrompt.__name__)) self.dialog_set.add( WaterfallDialog("main_dialog", [ self.GetUserName, self.DisplayChoiceList, self.GetProblem,
from shareplum import Site from shareplum import Office365 from shareplum.site import Version # DICT WITH THE INFO THAT YOU NEED TO FILL THE FORM INTO THE LIST upload_dict = {"ID":4,"ClientName":"JOHN RED","StreetAdrress":"120 BROADWAY","Created":"2020-05-05"} # Authenticate to Office365 Sharepoint authcookie = Office365('https://YOUR-NAME.sharepoint.com', username='******',password='******').GetCookies() site = Site('https://YOUR-NAME.sharepoint.com/sites/YOUR-SITE/', version=Version.v2016, authcookie=authcookie) sp_list = site.List('YOUR-LIST') # GET ALL LIST EXIST OF MY ACCOUNT sp_data = sp_list.GetListItems() # CHECK IF LIST IS ALREADY EXIST sp_dataListItems = sp_list.GetListItems(fields=['ID', 'Title']) for spResultData in sp_dataListItems: id = spResultData.get("ID") Title = spResultData.get("Title") # IF ALREADY EXIST MADE UPDATE OF THE LIST IF DOESNT EXIST MADE NEW LIST if id == "1" and Title == 'TEST': update_date = [upload_dict] sp_list.UpdateListItems(data=update_date, kind='Update') else: update_date = [upload_dict] sp_list.UpdateListItems(data=update_date, kind='New')
import requests from shareplum import Office365 from config import config # get data from configuration username = config['sp_user'] password = config['sp_password'] site_name = config['sp_site_name'] base_path = config['sp_base_path'] doc_library = config['sp_doc_library'] file_name = "cat_pic.jpg" # Obtain auth cookie authcookie = Office365(base_path, username=username, password=password).GetCookies() session = requests.Session() session.cookies = authcookie session.headers.update({'user-agent': 'python_bite/v1'}) session.headers.update({'accept': 'application/json;odata=verbose'}) # perform the actual upload with open( file_name, 'rb') as file_input: try: response = session.post( url=base_path + "/sites/" + site_name + "/Shared%20Documents/Forms/AllItems.aspx/_api/web/GetFolderByServerRelativeUrl('" + doc_library + "')/Files/add(url='" + file_name + "',overwrite=true)", data=file_input) except Exception as err: print("Some error occurred: " + str(err))
#Python package for geocode location from geopy.geocoders import Nominatim geolocator = Nominatim(user_agent="Simple Application") #Sharepoint site information server_url = "https://ytpl.sharepoint.com" site_url = "https://ytpl.sharepoint.com/sites/demosite/PowerApps/" username = "" passwd = "" leave_balance_list = 'lm_emp_leave_balance_record' leave_records_list = 'lm_employee_leave_record' #Get Authentication cookies authcookie = Office365(server_url, username=username, password=passwd).GetCookies() site = Site(site_url, authcookie=authcookie) #Get all the data from sharepoint list which holds employess leave balance record sp_list = site.List(leave_balance_list) #Get all the data from sharepoint list which holds employees leave records leave_records = site.List(leave_records_list) # Create an object of Flask Class and configure it run in debug mode app = flask.Flask(__name__) app.config["DEBUG"] = True #------------------------------------------------------------------------------------------------------ #Route to get leave balance based on user id (email address - for example [email protected]"
class Request(object): def __init__(self, name, item): self.name = name self.item = item self.email = "" user = config('iptvmail') pwd = config('pwd') emailist = [] authcookie = Office365('https://reutlingenuniversityde.sharepoint.com/', username=config('username'), password=config('password')).GetCookies() site = Site('https://reutlingenuniversityde.sharepoint.com/sites/Test01', authcookie=authcookie) sp_list = site.List('KK_Test_List_01') sp_list1 = site.List('Taschen_Liste') fields = ['Person', 'Item'] fields1 = ['Person', 'Tasche'] query = {'Where': [('Lt', 'EndDate', str(date.today()))]} data = pd.DataFrame(sp_list.GetListItems(fields=fields, query=query)[0:]).dropna(thresh=1) data1 = pd.DataFrame(sp_list1.GetListItems(fields=fields1, query=query)[0:]).dropna(thresh=1)
# -*- coding: utf-8 -*- """ Created on Thu Feb 20 11:22:12 2020 @author: FL014036 "*****@*****.**", "P@$$word" """ from shareplum import Site from shareplum import Office365 import pandas as pd authcookie = Office365('https://cocacolaflorida.sharepoint.com', username='******', password='******').GetCookies() site = Site('https://cocacolaflorida.sharepoint.com/Distribution/', authcookie=authcookie) sp_list = site.List('Hazardous Material Disclosure Statement') data = sp_list.GetListItems() data_df = pd.DataFrame(data) data_df = data_df[['Date', 'Drivers Name', 'Shipment number', 'DSD Location']]
from flask import Flask, jsonify, render_template, request import pandas as pd import pymysql from sqlalchemy import create_engine pymysql.install_as_MySQLdb() from shareplum import Site import json from shareplum import Office365 from flask_wtf.csrf import CSRFProtect csrf = CSRFProtect() app = Flask(__name__) csrf.init_app(app) app.config['SECRET_KEY'] = 'venkata789123' authcookie = Office365('https://svm12.sharepoint.com', username='******', password='******').GetCookies() site = Site('https://svm12.sharepoint.com/sites/GENIV', authcookie=authcookie) def connect_site(): return site @app.route('/label_new', methods=['GET', 'POST']) def labelmatrix_new(): site = connect_site() program = site.List('GENIV_Product_ADB2') feature = site.List('GENIV Features_ADB2') rel_name = site.List('GENIV Releases_ADB2') program_data = program.GetListItems('All Items') feature_data = feature.GetListItems('All Items')
x['Achieved result'] = x['Achieved result'].fillna(0) x['Achieved result'] = x['Achieved result'].replace([''], 0) ##GMS code x['GMS Code'] = x[['Indicator code', 'GMS Code']].apply(lambda x: fix_gms(*x), axis=1) #Export to Excel file output_data = pd.concat([output_data, x]) output_data.to_excel('Output.xlsx', index=False) #upload to sharepoint online #load libraries needed for sharepoint upload from shareplum import Site from shareplum import Office365 from shareplum.site import Version import pandas as pd #setup access to sharepoint online authcookie = Office365('https://urlname.sharepoint.com', username='******', password='******').GetCookies() site = Site('https://urlname.sharepoint.com/sites/', version=Version.v2016, authcookie=authcookie) folder = site.Folder('Shared Documents/Folder/') with open('Output.xlsx', mode='rb') as file: fileContent = file.read() folder.upload_file(fileContent, "Output.xlsx")
def __login(self, sharepoint_url, username, password): authcookie = Office365(sharepoint_url, username=username, password=password).GetCookies() return authcookie
from config import config from shareplum import Site from shareplum import Office365 from shareplum.site import Version # get data from configuration username = config['sp_user'] password = config['sp_password'] authcookie = Office365('https://xxxxxx.sharepoint.com', username=username, password=password).GetCookies() site = Site('https://xxxxxx.sharepoint.com/sites/sbdev/subtest01',version=Version.v365, authcookie=authcookie) newlist=site.AddList('My New List', description='Great List!', template_id='Document Library') print(newlist)
import requests from shareplum import Office365 # Obtain auth cookie authcookie = Office365('https://gruposimbio.sharepoint.com/sites/dev', username='******', password='******').GetCookies() session = requests.Session() session.cookies = authcookie session.headers.update({'user-agent': 'python_bite/v1'}) session.headers.update({'accept': 'application/json;odata=verbose'})
def __init__(self, url, folder_path, username, password): self.folder_path = folder_path authcookie = Office365(url, username=username, password=password).GetCookies() self.site = Site(site_url=url, authcookie=authcookie)
from sys import argv from timeit import default_timer as timer import time from datetime import datetime # Starting the timer start = timer() # Decoding the Sharepoint and SQL passwords pwd = E.decrypt(secret.sharepoint_password.encode("utf-8")) pwd1 = E.decrypt(secret.password.encode("utf-8")) # Printing to the console for easy debugging. print("Starting......................\n") # setting up the connection and authentication to sharepint site authcookie = Office365('https://foundationriskpartners.sharepoint.com', username=secret.sharepoint_username, password=pwd).GetCookies() def MetaData(): '''This function retreive metadat from the admin sharepoint list where there we specify the source SQL table and destination sharepoint list''' # Connecting to the Sharepoint site where the Sharepoint_Admin lists lives. site1 = Site( f'https://foundationriskpartners.sharepoint.com.us3.cas.ms/sites/bidash/', authcookie=authcookie) # Reading The Sharepoiny admin input global sp_list sp_list = site1.List('Adm SqlToSharepoint') # Reading the last records in the SQltoshqrepoint list (one sql table at time ) data = sp_list.GetListItems('All Items') return data
emp_mgt_classes = ['M/P Management', 'Executive', 'Faculty', 'Management'] emp_classes = [ 'Resident', 'Professional', 'Police/Fire Hourly', 'Fellowship Pre Doc', 'Post Doc', 'LTD', 'PAA/PRF/PolyTech', 'Police/Fire BW Sal', 'Police/Fire Admin', 'Non-Pay', 'Continuing Lecturer', 'Visiting Faculty', 'Graduate Student', 'Temporary', 'Police/Fire Mgmt', 'Limited Term Lecturer', 'M/P Professional', 'Service', 'Support', 'Clinical/Research', 'Intern', 'Residence Hall Counselor', 'Student' ] logging.info('Starting up...') fake = Faker() authcookie = Office365('https://purdue0.sharepoint.com', username='', password='').GetCookies() site = Site('https://purdue0.sharepoint.com/sites/HRIS', version=Version.o365, authcookie=authcookie) test_list = site.List('ELT-Test') employees = [] supervisor = None count = 0 for x in range(1, 10001): if supervisor == None or x % randint(3, 7) == 0: # print ("SUPER: {}\t COUNT: {}".format(supervisor, str(count))) count = 1 supervisor = fake.name()
from shareplum import Site from shareplum import Office365 from shareplum.site import Version import json import os wd = os.getcwd() json_path = os.path.join(wd, "src", "authentification", "sharepoint_authentification.json") with open(json_path, "r") as read_file: sp_auth = json.load(read_file) authcookie = Office365(sp_auth["url"], username=sp_auth["username"], password=sp_auth['password']).GetCookies() site = Site(sp_auth["url_site"], version=Version.v2016, authcookie=authcookie) folder = site.Folder('Github_upload') csv_path = os.path.join(wd, "src", "data", "51427.csv") with open(csv_path, 'r', encoding="Latin-1") as file: data = file.read() folder.upload_file(data, "51427.csv")
from shareplum import Site from shareplum import Office365 from shareplum.site import Version import os import sys authcookie = Office365('https://yourcompany.atsharepoint.com', username='******', password='******').GetCookies() site = Site('https://yourcompany.atsharepoint.com/sites/Your-Sites', version=Version.v2019, authcookie=authcookie) # set the version if necessary for root, subdirs, files in os.walk('/path/to/root/dir'): dest_folder = root.split('/path/to/root')[ 1] # this will get directory after /path/to/dir and its subdir folder = site.Folder( 'Shared Document/your_dir_ifany/%s' % dest_folder ) # this set destination directory or will create directory in sharepoint if doesn't exist for fname in files: fullfname = os.path.join(root, fname) # get the full path of source file with open(fullfname, mode='rb') as file: # read the file in binary fileContent = file.read() folder.upload_file(fileContent, fname) # upload the file