Package: robopulser
robopulseNOTE: This project is in ealry stage!This is robopulser—a small, single-task library. It is meant to update a timestamp in a database. The robopulser library is built around the SQLAlchemy package and is relatively open for customization.Why you would need such a thing?If your program performs actions like RPA automation and you'd like to have constant updates from the program to a database, robopulse is for you. Although it is written in Python and can be imported directly into Python code, it can also work as a stand-alone script with a single YAML configuration file.InstallationFor testing without any database:pipinstallrobopulserIf you want to use robopulse with a real database (not SQLite), you can download it with one of the optional dependencies. The following databases have been tested and proven working:pipinstallrobopulser[mssql]# pip install pymssqlpipinstallrobopulser[mysql]# pip install mysql-connector-pythonpipinstallrobopulser[postgress]# pip install psycopg2pipinstallrobopulser[postgress1]# pip install pg8000Using in Python scriptThere are two ways to use robopulser inside the Python script. You can use it with your own SQLAlchemy model, or let robopulser create an SQLAlchemy model for you using a simple YAML file containing database table parameters and a few important flags.Using with YAML fileNote that the configuration file is always the same among various databases. You can test robopulser using a local SQLite database (which is generated automatically by robopulser). And when you are ready to go live, just replace the connection parameters.Look at the example of the configuration file (example.yml):table_name:"PULSE_TABLE"columns:# Mandatory: `primary_key=True` (but column name can be any)-name:pidcolumn_type:String(1000)default:"UNIQUEPID-123"unique:Trueprimary_key:True# <--- IMPORTANT# Mandatory: `info: 'pulse'` and type DateTime (but column name can be any)-name:last_pulsecolumn_type:DateTimeinfo:'pulse'# <--- IMPORTANT# No special tags, just a regular (optional) column example-name:contact_infocolumn_type:String(1000)default:"emergency.contact@mail.com"# You can add more columns with data you want to monitor# - name: (...)Now save this configuration asexample.ymland (in the same directory) write a simple script:importrobopulser.robopulseraspulserpulser.yaml_pulse("example.yml")Without providing any additional parameters, robopulser will create a local SQLite database (local_pulse.db) and send a pulse to it.You will not see any logs, but you can add a logger (from Python's logging library), and robopulse will send a single log at the debug level. A recommended logger isrobolog, which is already optimized for RPA purposes.Using with SQLAlchemy ModelsIf you want to use robopulse inside your code using your own SQLAlchemy model class, you can do it as well. Let's reproduce the previous example in this way:# roboforge-solutions's suite:importrobopulser.robopulseraspulserfromrobologimportrobolog# sqlalchemy imports:fromsqlalchemyimportColumn,String,DateTimefromsqlalchemy.ormimportdeclarative_base# Creating robolog instance:log=robolog.get_logger()# Your own model class:Base=declarative_base()classMyPulseModel(Base):__tablename__="PULSE_TABLE"pid=Column("pid",String(100),primary_key=True,unique=True,default="UNIQUEPID-123")last_pulse=Column("last_pulse",DateTime,info="pulse")contact_info=Column("contact_info",String(1000),default="emergency.contact@mail.com")# Single pulse using model approach:pulser.model_pulse(Model=MyPulseModel,logger=log)Using outside Python scriptIn order to be able to run this as a stand-alone program that can be compiled to an.exefile or just launched from the console, you can modify the previous example by giving an argument parser. Also, you can use a shell script provided by the robolog library to get ready-to-use examples. After installing the robolog library, just type in your shell (tested on PowerShell, Windows 11):(venv)PSC:\Users\jankiwoj_box\Documents\projects\_test>pulser-templateGottemplate:example.ymlGottemplate:pulser.pyYou will get a YAML file (the same as in the first example) and the run script recognizing this YAML.You can give some flags to this script. Learn more using the -h flag:(venv)PSC:\Users\jankiwoj_box\Documents\projects\_test>python.\pulser.py-husage:pulser.py[-h][--yamlYAML][--conn_strCONN_STR][--driverDRIVER][--userUSER][--hostHOST][--nameNAME][--passwdPASSWD][--portPORT]Scripttocallrobopulser.yaml_pulsefunctionwithoptionalarguments.options:-h,--helpshowthishelpmessageandexit--yamlYAMLPathtoYAMLmodelconfigurationfile--conn_strCONN_STRConnectionstring(alternativetoremainingparameters.)--driverDRIVERDatabasedriver--userUSERDatabaseuser--hostHOSTDatabasehost--nameNAMEDatabasename--passwdPASSWDDatabasepassword--portPORTDatabaseportNote: you cannot pass a logger using parameters, but you can editpulser.pyscript and pass your logger straight into theyaml_pulsefunction in the same way as in the previous example.