Apr-02-2019, 02:15 PM
(This post was last modified: Apr-02-2019, 02:30 PM by ichabod801.)
Hello
I have2 python scripts that I need to combine to read a csv file line by line and take loop through the data in the csv exporting it via cURL to one POST and 2 PUT the main script is below. Right now in the script I have hardcoded in email address, employee ID and password (bold and underlined) (these are the items I need to extract from a csv and then loop back through the csv after it cURL through the POST, PUT, PUT
Any help would be greatly appreciated as I am a sys admin and not a programmer but I am on a deadline to get this completed
I have2 python scripts that I need to combine to read a csv file line by line and take loop through the data in the csv exporting it via cURL to one POST and 2 PUT the main script is below. Right now in the script I have hardcoded in email address, employee ID and password (bold and underlined) (these are the items I need to extract from a csv and then loop back through the csv after it cURL through the POST, PUT, PUT
Any help would be greatly appreciated as I am a sys admin and not a programmer but I am on a deadline to get this completed
import sys import requests url = 'https://domain.com/iredadmin/api' # Admin email address and password. admin = '[email protected]' pw = 'domainpassword' # Login r = requests.post(url + '/login', data={'username': admin, 'password': pw}) # Get returned JSON data data = r.json() if not data['_success']: sys.exit('Login failed') cookies = r.cookies # Create user: <user>@domain.com # (url + api endpoint , data = parameters # hard coded preferred language & mail quota requests.post(url + '/user/[b][email protected][/b][u][/u]', cookies=cookies, data={'cn': 'My Name', 'password': '[b]1@Password12345[/b][u][/u]', 'preferredLanguage': 'en_US', 'quota': '5120'}) # Update user: <user>@domain.com requests.put(url + '/user/[b][email protected][/b][u][/u]', cookies=cookies, data={'cn': 'My New Name', 'employeeid' : '[b]testID[/b][u][/u]', 'language': 'en_US', }) requests.put(url + '/ml/[email protected]', cookies=cookies, data= {'add_subscribers': '[b][email protected][/b][u][/u]', })THIS IS THE SECOND SCRIPT THAT READS THE CSV
import csv input_file = csv.DictReader(open("users.csv")) for row in input_file: plantid = str(row["plant number"]) passwd = str(row["password"]) emailaddrs = str(row["email address"]) print(plantid) print(passwd) print(emailaddrs)