Author: tom
-
Using Python to send http commands
I now play with Python to communicate with HTTP servers. The idea that signals are sent to a server and the answer is subsequently analysed. My first attempt is shown below: import urllib3 http = urllib3.PoolManager() resp = http.request('GET', 'http://van-maanen.com/') print(resp.data) print(resp.status) the output can be seen as a series of symbols that can be…
-
CRUD on Salesforce with Python
I wrote four programmes in Python that enable us to maintain tables in Salesforce. The four functionalities are: creating data, reading data, updating data and deleting data. The programmes The programmes are stored in accompanying zip file. The programmes follow more or less the same logic. The first part is getting access to the system.…
-
SOQL / Querying salesforce
Salesforce is a CRM tool that allows monitoring customer contacts. It also allows following leads. For back ground technicians, it is interesting to know that it is possible to query the data. The structure of the query language resembles a bit SQL. The structure “select fields from table”may sound familiar to our ears. However SOQL…
-
New script to set up user on SQL Server
Herewith, I provide another script to set up a user in the SQL Server environment. The idea is that a role is created on the database. The user that is subsequently created is then added as a member to that role. First, the login is created. It is created on the master database. CREATE LOGIN…
-
Joining in Pandas
Python has Pandas its tool to handle matrices, also known as dataframes in Pyhon speak. It is possible to join dataframes, much like joining tables. I found a nice example on the internet with several possible choices. As a first step, two dataframes were declared: import pandas as pd The first dataframe: customer=pd.DataFrame({‘id’:[1,2,3,4,5,6,7,8,9],’name’:[‘Olivia’,’Aditya’,’Cory’,’Isabell’,’Dominic’,’Tyler’,’Samuel’,’Daniel’,’Jeremy’],’age’:[20,25,15,10,30,65,35,18,23],’Product_ID’:[101,0,106,0,103,104,0,0,107],’Purchased_Product’:[‘Watch’,’NA’,’Oil’,’NA’,’Shoes’,’Smartphone’,’NA’,’NA’,’Laptop’],’City’:[‘Mumbai’,’Delhi’,’Bangalore’,’Chennai’,’Chennai’,’Delhi’,’Kolkata’,’Delhi’,’Mumbai’]}) The second…
-
Granting privs in SQL Server
Granting privs in SQL Server is done in three steps. As first step, one must create a login to the SQL Server. This can be seen as getting the entrance to the data fort. CREATE LOGIN lezer WITH PASSWORD = ‘password’ GO One must then get entrance to the database. One must create a user…
-
Dates in SQL server
SQL Server is has several possibilities to calculate elapsed time (such as age). Two approaches are possible. The first idea is to calculate the number of hours and divide this by the number of hours in a year. The other possibility is to make a distinction between the number of a day in a month…
-
Adding data to Salesforce
Below, I provide a simple Python programme which allows to add data from an external table to Salesforce. The programme uses simple_salesforce as a library. In the first few lines, the necessary libraries are imported. from simple_salesforce import Salesforceimport pyodbcimport pandas as pd Then the connection to Salesforce is created. sf = Salesforce(username=’datamigrationuser@pension4you.nl.pensiond2′, password=’password’, security_token=’security’,domain=’test’)…
-
Write records to Salesforce
Below, I provide a simple programme. The programme is written in Python. With Python, a library “salesforce_api” is used. With this library, one is able to insert records, query records and delete records in Salesforce. from salesforce_api import Salesforce client = Salesforce(username=’datamigrationuser@pension4you.nl.pensiond2′, password=’***’, security_token=’***’,is_sandbox=True) hx = client.sobjects.Contact.insert({‘LastName’: ‘Example’, ‘Email’: ‘test@example.com’}) print(hx) hx = client.sobjects.query(“SELECT Id…
-
Check in Python for Email address
Recently, I discovered a nice trick to check the Email addresses. It uses a check on the setup of Email addresses. They must contain an @ symbol. They must contain a dot etc. It runs as follows: import re hx = ‘jaouadÂÂtaheri@hotmail.com’ if not re.match(r”^[A-Za-z0-9.+-]+@[A-Za-z0-9._-]+.[a-zA-Z]$”, hx): print(hx,’ klopt niet Email adres ‘) else: print(‘Email ok**’)