Skip to content

Instantly share code, notes, and snippets.

View rdapaz's full-sized avatar

ricdeez rdapaz

View GitHub Profile
@rdapaz
rdapaz / VisioGuideAdd.py
Created September 1, 2020 02:36
Add Visio Guides
import win32com.client as c
vsApp = c.gencache.EnsureDispatch('Visio.Application')
vsApp.Visible = True
path = r'https://woodsideenergy-my.sharepoint.com/personal/ricardo_dapaz_woodside_com_au/Documents/Desktop/ABB Transmittal-AU-33220002-AUABB-WSE-00001/LNADs/VA6000DJ0076.XXX1~.vsd'
dwg = vsApp.Documents.Open(path)
pge = dwg.Pages('Drawing')
x_diff = 144.64
x_steps = 24.0
x_step_diff = float(x_diff/x_steps)
x_start_step = 9.84
@rdapaz
rdapaz / VisioGuides.py
Created July 9, 2020 03:54
Equidistant Guides in Visio (Using Python Script)
import win32com.client as c
vsApp = c.gencache.EnsureDispatch('Visio.Application')
vsApp.Visible = True
path = r'<file and path>.vsd'
dwg = vsApp.Documents.Open(path)
# TODO this range gets changed depending on the guides which need to be dragged and dropped on the sheet
guides = [f'Sheet.{x}' for x in range(1474, 1492)]
print(guides)
print(dwg.Pages('<TheSheet>').Name)
refShape = 'REFGUIDE'
@rdapaz
rdapaz / extractOtter.py
Created June 18, 2020 16:28
Extract book topics from Otter export
import re
rex = re.compile(r'([A-Za-z ]+)(?:[\., ]+)?([pPaAgGeE]{4},?(?:[\., ])?\d\d?\d?)')
# Info below comes from Otter text export (no reader ID, no timestamp)
# Topics are read out and then Page Number are read at the end
# Does reasonable job
data = """
ICS concepts.
@rdapaz
rdapaz / word_search_and_replace.py
Created June 4, 2020 06:17
MS Word - Search and Replace
import win32com.client as c
import pprint
import re
class Util:
@staticmethod
def pretty_printer(o):
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(o)
@rdapaz
rdapaz / generateDocFromYAMLData.py
Last active May 22, 2020 07:06
Generate document from data
# coding: utf-8
import os
import sys
import pprint
import win32com.client
import yaml
def pretty_printer(o):
@rdapaz
rdapaz / changespreadsheet.py
Created May 22, 2020 07:04
Change values in a spreadsheet from a Python dictionary of old to new values
import re
import win32com.client as c
subs = """
One|1
Two|2
""".splitlines()
subs = {k: v for k, v in [y.split('|') for y in subs if len(y) > 0]}
xlApp = c.gencache.EnsureDispatch('Excel.Application')
@rdapaz
rdapaz / GenerateCiscoConfig.py
Created May 22, 2020 07:00
Using Jinja2 inline template to generate cisco switch changes
import re
import win32com.client as c
from jinja2 import FileSystemLoader, Environment, Template
xlApp = c.gencache.EnsureDispatch('Excel.Application')
xlApp.Visible = True
path = r'path.xlsx'
wk = xlApp.Workbooks.Open(path)
sh = wk.Worksheets('Sheet1 (2)')
@rdapaz
rdapaz / Visio_Bulk_Find_and_Replace.py
Last active May 22, 2020 05:18
Python script to do a visio find and replace
import re
import win32com.client as c
class VisioDrawing:
def __init__(self, path, pageName):
self.path = path
self.vsdApp = c.gencache.EnsureDispatch('Visio.Application')
self.vsdApp.Visible = True
self.vsd = self.vsdApp.Documents.Open(path)
@rdapaz
rdapaz / palo_alto_get_config_in_set_format.cfg
Created April 28, 2020 08:48
Palo Alto Firewalls: Get configuration in set mode format
set cli pager off
set cli config-output-format set
configure
show
@rdapaz
rdapaz / web_video_control.bash
Created April 16, 2020 08:41
osoyoo robot video control
cd ~/osoyoo-robot/cam-robot/mjpg-streamer/
sudo ./start.sh
sudo webiopi -d -c /etc/webiopi/config
Then navigate to http:10.11.12.122:8000