Automation – jack of all trades master of some https://jackofalltradesmasterofsome.com/blog Consultant - Real Estate - Author - Business Intelligence Sun, 04 Apr 2021 22:44:48 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 Automate your Twitter with API and Python – Robotic Python Automation https://jackofalltradesmasterofsome.com/blog/2020/06/18/automate-your-twitter-with-api-and-python-robotic-python-automation/ Thu, 18 Jun 2020 21:33:03 +0000 http://jackofalltradesmasterofsome.com/blog/?p=848 Sometimes you do not want to spend money to do things are are really easy. Tools like Hootsuite or Buffer can run you 100’s a month for something you can roll out yourself for free and a hour or so worth of work. Let’s learn how to Automate your Twitter with API and Python

Setting Up Twitter

First we will want to create a Twitter Account and Handle and register for a developer account. This may take a few days for you to get approved.

  1. Create a Twitter Account
  • After a few more steps you will have a working Twitter Account
  • If you have not verified a phone number, it will make you do that now.
  • The next few screens will have you fill out why you want to use the portal and review and sign a developers agreement.
  • You will than need to wait for your account to be confirmed

Creating an Twitter App

  1. Once you app is Confirmed, you can create an app to get an API key
  • Obtain your consumer keys and your access tokens, once the app is created

Create a CSV for Data

  1. Create a CVS File called “post.csv” with your post message, hashtags and urls. If this is not in the same folder as your Python script this will need to be updated in the next steps

Creating a Python Application

  1. Create a new python application and run the command “pip install tweepy” to install the library
pip install tweepy
  • Import your excel file into a dataframe and use the sample command to select a random row. Place each of these values in their own variables.
import pandas as pd
df = pd.read_csv('post.csv')

#print (df)

df2 = df.sample()

title = df2.iloc[0]['Title']
hashtags = df2.iloc[0]['hashtags']
url = df2.iloc[0]['url']

print (title)
print (hashtags)
print (url)
  • The following code can now be use to auto post your first twitter message once you replace your keys!
import tweepy

def main():
    twitter_auth_keys = { 
        "consumer_key"        : "REPLACE_THIS_WITH_YOUR_CONSUMER_KEY",
        "consumer_secret"     : "REPLACE_THIS_WITH_YOUR_CONSUMER_SECRET",
        "access_token"        : "REPLACE_THIS_WITH_YOUR_ACCESS_TOKEN",
        "access_token_secret" : "REPLACE_THIS_WITH_YOUR_ACCESS_TOKEN_SECRET"
    }
 
    auth = tweepy.OAuthHandler(
            twitter_auth_keys['consumer_key'],
            twitter_auth_keys['consumer_secret']
            )
    auth.set_access_token(
            twitter_auth_keys['access_token'],
            twitter_auth_keys['access_token_secret']
            )
    api = tweepy.API(auth)
 
    tweet = title + ' ' + hashtags + ' ' + url
    status = api.update_status(status=tweet) 
 
if __name__ == "__main__":
    main()

Interested in learning more? Check out our blog post on an Introduction to Python Class.

Automate your Twitter with API and Python – Robotic Python Automation

]]>
Robotic Python Automation – Python to Create Abstract Art Automatically https://jackofalltradesmasterofsome.com/blog/2020/05/13/robotic-python-automation-python-to-create-abstract-art-automatically/ Wed, 13 May 2020 16:37:43 +0000 http://jackofalltradesmasterofsome.com/blog/?p=834 Robotic Python Automation – Python to Create Abstract Art Automatically

Looking to spruce up your home office? Here is a quick fun project you can do in Python to Create Abstract Art Automatically to print out for your home! This tutorial uses the basics of working with images, files, math and basic loops to create images you can color in however you like to match the style of your home.

Check out my free Udemy Classes here to learn Python for free! And be sure to check out my books for additional free educational material. Other materials can be found here.

  • Create a new Jupyter Notebook in the following location “C:\Users\yourusername\Documents\Python\Training\”
  • Create a new folder on your C Drive “C:\Users\yourusername\Documents\Python\Training\art” and create a empty file called “template.png” with a transparent background.
  • Install pillow so we can work with images in Python
pip install pillow
  • We than use numpy and matplot lib to generate a random shape with the following code. Change some of the constants below to experiment with generating different shapes. The loop (i) can also be changes to generate more or less shapes. This will create 25 shape in Python which you can see in Juptyer and also save them to the art folder.
from matplotlib.path import Path
import matplotlib.patches as patches
import numpy as np
from matplotlib import pyplot as plt

i=1

while i<20: 
    # UPDATE THESE VARIABLES TO CHANGE THE TYPES OF SHAPES
    n = 4 # Number of possibly sharp edges
    r = 0.7 # magnitude of the perturbation from the unit circle, 
    # should be between 0 and 1
    N = n*3+1 # number of points in the Path
    # There is the initial point and 3 points per cubic bezier curve. Thus, the curve will only pass though n points, which will be the sharp edges, the other 2 modify the shape of the bezier curve

    angles = np.linspace(0,2*np.pi,N)
    codes = np.full(N,Path.CURVE4)
    codes[0] = Path.MOVETO

    verts = np.stack((np.cos(angles),np.sin(angles))).T*(2*r*np.random.random(N)+1-r)[:,None]
    verts[-1,:] = verts[0,:] # Using this instad of Path.CLOSEPOLY avoids an innecessary straight line
    path = Path(verts, codes)

    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    patch = patches.PathPatch(path, facecolor='none', lw=0.5)
    ax.add_patch(patch)

    ax.set_xlim(np.min(verts)*1.1, np.max(verts)*1.1)
    ax.set_ylim(np.min(verts)*1.1, np.max(verts)*1.1)
    ax.axis('off') # removes the axis to leave only the shape
    
    plt.savefig('art/foo'+str(i)+'.png', transparent=True, dpi=300)
    
    i=i+1
  • In our last step all we need to do now is loop through each of the files we created and pasting them into the template image. We use the random function to paste them into random spots on the new image and then save the file as “workofart.png”. This create a cool new pattern on a transparent background!

from PIL import Image, ImageDraw
import numpy as np
import os
import random

i=1
#os.remove("art/workofart.png")
background = Image.open("art/template.png")


while i<20: 
    foreground = Image.open("art/foo"+str(i)+".png")
    background.paste(foreground, (random.randint(-1000,1000), random.randint(-1000,1000)), foreground)
    background.save("art/workofart.png")
    i=i+1
    

background.close()
foreground.close()  

The last step is have some fun. Use your favorite paint colors. Once completed, take over to your local print shop and put in a frame above your desk! Take a look at the artwork I created below.

Check out my free Udemy Classes here to learn Python for free! And be sure to check out my books for additional free educational material. Other materials can be found here.

Robotic Python Automation – Python to Create Abstract Art Automatically

]]>
Robotic Python Automation – Automating Working with Files with Python. (Cleaning, Sorting and Archiving) https://jackofalltradesmasterofsome.com/blog/2020/05/12/robotic-python-automation-automating-working-with-files-with-python-cleaning-sorting-and-archiving/ Tue, 12 May 2020 17:28:06 +0000 http://jackofalltradesmasterofsome.com/blog/?p=792 Robotic Python Automation Files Cleaning Sorting and Archiving.

Sometimes we have folders where files are saved that get out of control. Sometimes we have Excel documents or Work files that pile up and we need an efficient way to sift and sort through them and either archive files or delete them. Using Python, we can build a script that automatically completes two tasks.

  1. Looks for files of a certain name and archives them
  2. Looks for files older than a certain data and deletes them

Setup

  1. Create a new Jupyter Notebook and name it Document_Automation
  • Create a new folder on your C Drive “C:\Python\Automation” and seed it with 10 empty files that follow the naming conventin file_YYYYMMDD and log_YYYYMMDD. Create two folders called “Files” and “Logs”

Setup

  • The following command will list out all text files located in the folder you are searching for and place the date in to a list called “mylist”. The “*” is a wildcard that allows you to search for all character combinations that end with “.txt”. This can be updated to look for other file types
import glob
mylist = glob.glob("C:/Python/Automation/*.txt")
print(mylist)
  • Next we can try to create our folders where we will organize our files. Since we already created them, the try/catch will fail but if you had deleted them you will see them reappear. The OS and shutil need to be imported for these commands to work
import os, shutil
try: 
    os.mkdir("C:/Python/Automation/Files")
    os.mkdir("C:/Python/Automation/Files")
except OSError:
     print ("Folder Creation Failed")
else:
    print ("Folder Creation Success")

  • Start with a loop to go through your list
for i in mylist: 
     print(i)
  • Lets update the look to search for any “log” first. This can be done with a string startswith() command or using the “in” command with an If statement. Both work in the case but be careful if your file naming rules can change. We will use the latter example for the rest of the tutorial.
for i in mylist: 
    if (i.startswith('C:/Python/Automation\log_')):
        print(i)

for i in mylist: 
    if ("log" in i):
        print(i)

  • Now move the files found in the search to the destination folder using the Move command. We need to specify the source location and destination location so we use Replace string manipulation to create both of those strings to pass to the function. Once run, you will see the files moved to the respective folders.
for i in mylist: 
    if ("log" in i):
        #print(i)
        source = i
        destination = i.replace('C:/Python/Automation', 'C:/Python/Automation/Logs') 
        shutil.move(source, destination)
  • We can now do the same with the files titled “Files”
for i in mylist: 
    if ("file" in i):
        #print(i)
        source = i
        destination = i.replace('C:/Python/Automation', 'C:/Python/Automation/Files') 
        shutil.move(source, destination)

Cleaning out old Files

  • Finally, we want to delete any old files. We can do this using the remove and time functions in Python to identify the last modified time of the file. In this sample 1800 is 30 minutes in seconds. This can be adjusted to make the window longer or a few days. We need to import time and sys to be able to the correct commands. Uncomment the If statement to use parameters on the time duration.
import os, time, sys

path = r'C:/Python/Automation/Logs'

now = time.time()

for f in os.listdir(path):
    #if os.stat(os.path.join(path,f)).st_mtime < now - 7 * 86400:
    if os.stat(os.path.join(path,f)).st_mtime < now:
        print("Removing File")
        os.remove(os.path.join(path,f))

Check out my these Udemy Classes below to get started in Python

And Other articles here below.

Robotic Python Automation Files Cleaning Sorting and Archiving

]]>
Bridging the Owner to Property Manager Data Gap https://jackofalltradesmasterofsome.com/blog/2018/08/10/bridging-the-owner-to-property-manager-data-gap/ Fri, 10 Aug 2018 19:33:54 +0000 http://jackofalltradesmasterofsome.com/blog/?p=104 One of the more common reoccurring problems seen in the real estate space is the disconnect between the data created and stored by the individual property managers and the transfer of that very data to the respective owners, operators and fund managers. In most scenarios, individual property managers are using management and accounting tools of their choosing or one that was already in production use prior to when the property was acquired. In this (very common) scenario, the owners end up with multiple properties and multiple property managers each using different systems, processes and accounting timelines. Let’s take a look at Bridging the Owner to Property Manager Data Gap.

In this situation, owners must employ a team of analyst’s whose job is to collect the different exported file formats from each manager, clean and consolidate into one central source, usually a massive Excel spreadsheet. This leads to a few common issues.

  • Data is provided in different formats and a manual mapping exercise must take place every month end.
  • All the manual steps and consolidation of data sheets introduce risk of dirty data and data errors.
  • The manpower required could be spent elsewhere had the process been streamlined and automated.
  • Data history is now preserved in a series of Excel sheets on a shared drive
  • Files sent from managers to owners are usually sent via email. This introduces a security risk as well as a data retention problem.

The solution to this problem is not specific to the real estate space rather building safeguards and efficiencies into this process is a data transfer solution that can be implemented across industries that have to deal with disparate flat file data sources coming from out of the network. In a more common solution you have the following architecture.

  • The property managers would be instructed to use easy to use and inexpensive encryption software like PGP, once their file processing is complete at month end.
  • The files would then be saved to an SFTP such as ShareFile, ensuring secure file transfers. This process usually can be automated based on the source tools capabilities, but manual loads are not uncommon either.
  • This is where the true automation is built. A process on the owner’s side using simple high-level data transfer languages can be used to download, decrypt and and archive the files from the SFTP automatically. This will allow raw files to be stored for future reference.
  • Once the file is decrypted, the process would have a set of mapping and translation rules to convert and conform the data into a standard and clean format. This removes the risk of human related data errors that could be introduced.
  • Data is stored to a database rather then an Excel document. This allows for larger datasets to be stored and queried by the analyst team. Data from the database can be extracted to Excel or a reporting tool for future analysis but the primary source of data remains the database, eliminating multiple copies of excel documents floating around the organization.
]]>
Automate your Real Estate Software – Yardi ETL and Automation https://jackofalltradesmasterofsome.com/blog/2018/04/05/automate-real-estate-software-yardi-etl-automation/ Thu, 05 Apr 2018 20:23:07 +0000 http://jackofalltradesmasterofsome.com/blog/?p=53 Interesting in learning how to Automate your Real Estate Software – Yardi ETL and Automation. This blog post will help you drive your CRE business forward.

When running your Real Estate business, it helps to not have to think about the small things. This is where process automation can help free up time for your resources and eliminate the risk of missing tasks or checklist items when certain actions occur.

Need help with getting this solution up and running for your business? Email me at bettermentstudio5@gmail.com to discuss a low cost solution to host your reporting, analytics and integration needs!

If the contents of this post are outside of your wheelhouse, don’t worry, this is why I started CREXchange.io to help clients get up and off the ground with Yardi Data Integration and Advanced Power BI Custom Reports to help run your CRE business. Contact us there for more details or a demo!

For example, most of your Property ERP like Yardi will automatically book transactions to the ledger and to the tenant at the beginning of the month for rent, or automatically trigger an email notification when the lease is nearing sixty days to completion. But there are many tasks that are unique to your business that need to occur without thought based on the rules you have defined, and some of these tasks will not be readily available in your tools automation drop downs.

Supplementing your tools automation can be completed with smart SQL stored procedures. When using tools like Yardi, there are data flows that can be created using the Task Runner Tool. This tool can be used to kick off steps like property list rebuilds or refreshing of occupancy. But when combined with called to custom stored procedures, you can use it to automate property onboarding from 3rd party systems.

Another clever way to utilize stored procedures is to auto trigger payments and charges. For example, as a tenant moves through the eviction process, you can check for status changes to certain fields to trigger charges directly to the tenant. A high-level screenshot is shown below.

Overall, if you have database access to your core system you can be as creative as you like with making sure processes are followed by elimination humans from the steps and making sure the data drives your business instead.

Automate your Real Estate Software – Yardi ETL and Automation

]]>