• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

Debugging Python- Have your best debug code at the tip of your fingers

debugging pythonDebugging Python

I’m learning how to program in Python and have put together some decent gui code which can be very helpful when trouble-shooting your code.

Trying to solve issues by just looking at your code can be done but it isn’t nearly as fast as using some real debugging python code.

 

AutoHotKey Debugging Python code

 
#Persistent
#SingleInstance , Force
#NoEnv
Menu, tray, icon, B:ProgsIconsProgsPython.ico, 1
;**********************Py_Lists*********************************
Menu,Py_Lists,Add, Count of x,            Py_Lists_Count

Menu,Py_Lists,Add, Append,                Py_Lists_Append
Menu,Py_Lists,Add, Concatenate,           Py_Lists_Concatenate
Menu,Py_Lists,Add, Insert,                Py_Lists_Insert
Menu,Py_Lists,Add, Pop,                   Py_Lists_Pop
Menu,Py_Lists,Add, Remove,                Py_Lists_Remove
Menu,Py_Lists,Add, Replace x,             Py_Lists_Replace
Menu,Py_Lists,Add, Reverse,               Py_Lists_Reverse
Menu,Py_Lists,Add, Sort,                  Py_Lists_Sort

;**********************Py_Strings*********************************
	;**********************Py_Strings_Case*********************************
	Menu,Py_Strings_Case,Add, Cap 1st Letter,      Py_Strings_Capitalize_first
	Menu,Py_Strings_Case,Add, Lowercase,           Py_Strings_Lower
	Menu,Py_Strings_Case,Add, Uppercase,           Py_Strings_Upper
	Menu,Py_Strings_Case,Add, Title case,          Py_Strings_Title	

Menu,Py_Strings,Add, Change Case, :Py_Strings_Case
	;**********************Py_Strings_Slice*********************************
	Menu,Py_Strings_Slice,Add, Slice me,      Py_Strings_Capitalize_first
Menu,Py_Strings,Add, Slicing, :Py_Strings_Slice
	;**********************Py_Strings_Return*********************************
	Menu,Py_Strings_Return,Add, Count of Substring,  Py_Strings_Count
	Menu,Py_Strings_Return,Add, index of Substring,  Py_Strings_Find
	Menu,Py_String_Returns,Add, Length,              Py_Strings_Length
Menu,Py_Strings,Add, Index and Counts, :Py_Strings_Return
	
	;**********************Py_Strings_Append_Trim*********************************
	Menu,Py_Strings_Append_Trim,Add, LTrim,          Py_Strings_LTrim
	Menu,Py_Strings_Append_Trim,Add, Strip (drops front and back),Py_Strings_Strip
	
Menu,Py_Strings,Add, Append / Trim, :Py_Strings_Append_Trim

	;**********************Py_Strings_Regex*********************************
	Menu,Py_Strings_Regex,Add, email,          			 Py_Strings_Regex_Email
	Menu,Py_Strings_Regex,Add, Match -named subvars,  	 Py_Strings_Regex_Named_Match
	Menu,Py_Strings_Regex,Add, Split on Whitespace, 	 Py_Strings_Regex_Split_WhiteSpace
	Menu,Py_Strings_Regex,Add, Split on range in needle, Py_Strings_Regex_Split_On_Range
Menu,Py_Strings,Add, RegEx, :Py_Strings_Regex

;*******************************************************
;*******************************************************
;**********************Tuples*********************************
Menu, Py_Tuples, Add, Sort, 							Py_Tuple_Sort
Menu, Py_Tuples, Add, Functions Available, 				Py_Tuple_Avail_Funcs
	Menu,Py_Change_Case,Add, Lowercase Tuple,			Py_Tuple_LowerCase
	Menu,Py_Change_Case,Add, Uppercase Tuple,			Py_Tuple_UpperCase
Menu,Py_Tuples,Add, Change Case, 						:Py_Change_Case
;*******************************************************
;**********************Stats*********************************
;*******************************************************
;**********************Pandas*********************************
;**********************Panda Options*********************************
Menu,Py_Pandas_Options,Add, Have df wrap columns,		Py_Pandas_Options_Expand_Frame
Menu,Py_Pandas_Options,Add, Width of your disply,	 	Py_Pandas_Options_Width
Menu,Py_Pandas_Options,Add, Max column width, 			Py_Pandas_Options_Max_Col_Width
Menu,Py_Pandas_Options,Add, Max # columns,	 			Py_Pandas_Options_Max_Col
Menu,Py_Pandas_Options,Add, Max # rows, 				Py_Pandas_Options_Max_Rows
Menu,Py_Pandas_Options,Add,
Menu,Py_Pandas_Options,Add, Column Header Justification,Py_Pandas_Options_ColHead_Justify
Menu,Py_Pandas_Options,Add, Number of decimal places ,	Py_Pandas_Options_Precision
Menu,Py_Pandas_Options,Add, Default encoding, 			Py_Pandas_Options_Encoding
	Menu,Py_Pandas,Add, Options, :Py_Pandas_Options
;**********************Panda Data Frame*********************************
		Menu,Py_Pandas_DataFrame,Add, Select Multiple Columns, 			Py_Pandas_DataFrame_Col_Select
		Menu,Py_Pandas_DataFrame,Add, Frequency Count on Column,		Py_Pandas_DataFrame_Col_Count
		Menu,Py_Pandas_DataFrame,Add, Filter Column on Single value,	Py_Pandas_DataFrame_Col_Filter_Single
		Menu,Py_Pandas_DataFrame,Add, Filter Column on Multiple values,	Py_Pandas_DataFrame_Col_Filter_Multiple
	Menu,Py_Pandas,Add, DataFrame, :Py_Pandas_DataFrame
	
		Menu,Py_Pandas_Graph, Add, Graph necessities for plot,  		Py_Pandas_Graph_Graph_Necess
	Menu,Py_Pandas,Add,Graph, :Py_Pandas_Graph
;*******************************************************
menu,Py_Tuples 		,Add, Tuple example, 						Py_DUMMY_PLACEHOLDER
menu,Py_Stats  		,Add, Pandas, 						:Py_Pandas
menu,Py_Dictionaries,Add, Dictionaries example, 				Py_DUMMY_PLACEHOLDER

;**********************Convert Vars*********************************
Menu,Py_Convert		,Add, Convert Integer to String,     		Py_Convert_To_String
Menu,Py_Convert		,Add, Convert String to Integer,     		Py_Convert_To_Integer
Menu,Py_Convert		,Add, Convert String to Float,  	   		Py_Convert_To_Float
Menu,Py_Convert		,Add,
Menu,Py_Convert		,Add, Convert List to Tuple,	     		Py_Convert_List_to_Tuple
Menu,Py_Convert		,Add, Convert Tuple to List,	     		Py_Convert_Tuple_To_List

;*******************************************************;*******************************************************
;*******************************************************;*******************************************************
;**********************verbs*********************************
;*******************************************************;*******************************************************
;*******************************************************;*******************************************************
	Menu,Py_Funcs_FruitLess,Add,Fruitless Functions, 		Py_DUMMY_PLACEHOLDER
Menu,Py_Funcs	,Add, Fruit LESS Functions, 		:Py_Funcs_FruitLess

	Menu,Py_Funcs_Fruitful,Add,Fruitful Functions, 				Py_DUMMY_PLACEHOLDER
Menu,Py_Funcs	,Add, Fruit FULL Functions, 		:Py_Funcs_Fruitful

	Menu,Py_Loops_While	,Add, Iterate through object, 			Py_DUMMY_PLACEHOLDER
	Menu,Py_Loops_While	,Add, Dedupe, 							Py_DUMMY_PLACEHOLDER
Menu,Py_Loops,Add, While,  	:Py_Loops_While

	Menu,Py_Loops_For	,Add, While loops, 						Py_DUMMY_PLACEHOLDER
Menu,Py_Loops,Add, For,  	:Py_Loops_For
;*******************************************************
;**********************Debugging Python*********************************

Menu,Py_Debugging,Add, Python Path, 						Py_Python_Path
Menu,Py_Debugging,Add, Global Variables and their types,	Py_Globals
Menu,Py_Debugging,Add, Local Variables and their types,		Py_Locals
Menu,Py_Debugging,Add, Structure / Shape,					Py_StructShape
Menu,Py_Debugging,Add, Interactive mode in SciTE,			Py_Interactive
Menu,Py_Debugging,Add, Display Documentation,				Py_Display_Doc
Menu,Py_Debugging,Add, Display Help via Browser,			Py_Display_Help_HTML
Menu,Py_Debugging,Add, List installed Modules and Version,	Py_Installed_Modules_Versions

;**********************Tools  / Utils*********************************
Menu,Py_Tools_Utils,Add, Print function with optional title,Py_Tools_Utils_Print
Menu,Py_Tools_Utils,Add, Current date/time 				   ,Py_Tools_Utils_Date_Time
Menu,Py_Tools_Utils,Add, Launch iPython,					Py_Tools_Utils_iPython

;**********************Python Main menu*********************************
Menu,Python, Add, Lists,       	:Py_Lists
Menu,Python, Add, Strings,     	:Py_Strings
Menu,Python, Add, Tupless,     	:Py_Tuples
Menu,Python, Add, Dictionaries,	:Py_Dictionaries
Menu,Python, Add, Convert Vars,	:Py_Convert
Menu,Python, Add, Stats,		:Py_Stats
Menu,Python, Add,  ;blank line to separate
Menu,Python, Add, Functions,	:Py_Funcs
Menu,Python, Add, Loops,		:Py_Loops
Menu,Python, Add,  ;blank line to separate
Menu,Python, Add, Debugging,		:Py_Debugging
Menu,Python, Add, Tools / Utilities,:Py_Tools_Utils
;~ Menu,Python, Add, Non-Fruitful Functions,:Py_Fruit_Func

^+Lbutton::Menu, Python, Show  ; Control + Left mouse button
;*******************************************************
Py_DUMMY_PLACEHOLDER:
return

;**********************Debugging*********************************
Py_Python_Path:
ClipProcess("import sys  # Shows Executable, bitness and paths`r`nprint ""rExecutable:"",sys.executable,""r  Platform:"",sys.platform,""r""`r`nfor i in sorted(sys.path): print ""      Path: "",i`r`n")
Return

Py_Globals:
ClipProcess("for varname,value in globals().items():`r`n  print varname,' = ',value,' : ',type(value)  # Prints global variables")
return
Py_Locals:
ClipProcess("for varname,value in locals().items():`r`n  print varname,' = ',value,' : ',type(value)  # Prints Local variables")
return
Py_StructShape:
ClipProcess("from structshape import structshape  #prints structure and shape of object from Think Python`rprint structshape(MyVar)")
return

Py_Interactive:
ClipProcess("import code; code.interact(local=locals())  #Allows shell w/in SciTe- look at output window")
return

Py_Display_Doc:
ClipProcess("help(MyModule)  # swap out MyModule with Method or object")
return

Py_Display_Help_HTML:
ClipProcess("import os `; os.system('python -m pydoc -g')  #Display help in HTML")
return

Py_Installed_Modules_Versions:
ClipProcess("import pip; print('n'.join(sorted(['%s=%s' % (i.key, i.version) for i in pip.get_installed_distributions()])))  #Lists installed Python Modules and their versions")

return
;**********************Python*********************************
Py_Lists_Append:
ClipProcess("MyList.append(x)  # Add an item to the end of the list; x is new item")
Return

Py_Lists_Count:
ClipProcess("ct = MyList.count('a')  # Return the number of times x appears in the list")
Return

Py_Lists_Concatenate:
ClipProcess("MyList + [36,49,64]  # Concatenate values to list")
Return

Py_Lists_Insert:
ClipProcess("MyList.insert(7,'Insert 7')  # Insert item at position. MyList.insert(0,'32') inserts 32 at beginning")
Return

Py_Lists_Pop:
ClipProcess("MyList.pop(7)  # Remove item at position in the list, AND RETURN IT. If no index is specified, removes and returns the last item. (The brackets around the i denote that the parameter is optional)")
Return

Py_Lists_Remove:
ClipProcess("MyList.remove('text')  # Remove the FIRST item from the list whose value is x. It is an error if there is no such item.")
Return

Py_Lists_Replace:
ClipProcess("MyList[7]= '65'  # Replace the indexed value with 65")
Return

Py_Lists_Reverse:
ClipProcess("MyList.reverse()  # Reverse the elements of the list")
Return

Py_Lists_Sort:
ClipProcess("list_Name.sort(cmp=None, key=None, reverse=False)  # Sort the items of the list in place (the arguments can be used for sort customization, see sorted() for their explanation).")
Return
;**********************Python Strings*********************************
Py_Strings_Capitalize_first:
ClipProcess("MyVar = MyVar.capitalize()  # Use w/o 'MyVar =' if you don't need to change original variable")
return

Py_Strings_Count:
ClipProcess("ct = MyVar.count('l',0,33) # Return the # of non-overlapping occurrences of substring sub in the range (range is optional)")
Return

Py_Strings_Find:
ClipProcess("i = MyVar.find('l',0,33)  # Return the lowest index in the string where substring sub is found. Returns -1 if not found")
Return

Py_Strings_Length:
ClipProcess("len(MyVar)  # obtain length of string")
Return

Py_Strings_Lower:
ClipProcess("MyVar = MyVar.lower()  # Use w/o 'MyVar =' if you don't need to change original variable")
Return

Py_Strings_LTrim:
ClipProcess("MyVar = MyVar.lstrip('trim')  # Return a copy of the string with leading characters removed. (Removes whitespace if no charcters provided")
Return

Py_Strings_Strip:
ClipProcess("MyVar = MyVar.strip('trim')  # Return a copy of the string with leading and ending characters removed. (Removes whitespace if no charcters provided")
Return
Py_Strings_Upper:
ClipProcess("MyVar = MyVar.upper()  # Use w/o 'MyVar =' if you don't need to change original variable")
Return

Py_Strings_Title:
ClipProcess("MyVar = MyVar.title()  # Use w/o 'MyVar =' if you don't need to change original variable")
Return

;**********************REgex*********************************
Py_Strings_Regex_Email:
ClipProcess("import re`rstr = 'purple alice-b@google.com monkey dishwasher'`rmatch = re.search('([w.-]+)@([w.-]+)', str)`rif match:`r    print match.group()   ## 'alice-b@google.com' (the whole match)`r    print match.group(1)  ## 'alice-b' (the username, group 1)`r    print match.group(2)  ## 'google.com' (the host, group 2)")
Return

Py_Strings_Regex_Named_Match:
ClipProcess("import re`r######### Named Regex extracting address`rname = r'[a-zA-z_]w+'`rneedle = '(?:' + name + ')'`rhaystack='Joe King 836 Kilbridge Ln.  Coppell  tx  75029nJoe Two 836 Kilbridge Ln.  Coppell  tx  75029'`rneedle='(?P<First_Name>w+)s+(?P<Last_Name>w+)s+(?P<Address>d{1,5}s+w+s+w+.?)s+(?P<City>w+)s+(?P<State>ww)s+(?P<Zipcode>d{1,5})'`rm = re.match(needle, haystack,re.I)`rprint m.group('First_Name'),m.group('Last_Name'), m.group('Address'), m.group('City'), m.group('State').upper(),m.group('Zipcode')")
return

Py_Strings_Regex_Split_WhiteSpace:
ClipProcess("import re`rprint(re.split(r'(s*)', 'heare are some words'))  # s is whitespace and splits Haystack")
Return

Py_Strings_Regex_Split_On_Range:
ClipProcess("import re`rprint(re.split(r'[a-fA-F]', 'jfdsklajfkeawfjkSawDFaw',re.I|re.M)) #splits on range listed in needle")
Return
;*******************************************************
;**********************Tuples*********************************
Py_Tuple_Avail_Funcs:
ClipProcess("print(dir(MyTuple))  # List of functions available on Tuple")
Return

Py_Tuple_UpperCase:
ClipProcess("Lower_MyTuple=[x.lower() for x in MyTuple]  #List comprehension on Tuple")
return

Py_Tuple_LowerCase:
ClipProcess("Upper_MyTuple=[x.upper() for x in MyTuple]  #List comprehension on Tuple")
return

Py_Tuple_Sort:
ClipProcess("s=sorted(MyTuple)  #Sort tuple")
return
;*******************************************************
;**********************stats*********************************
;**********************pandas*********************************
;**********************Pandas Options*********************************
Py_Pandas_Options_width:
ClipProcess("pd.options.display.width = 1000  #Set default width")
return
Py_Pandas_Options_Max_Col_Width:
ClipProcess("pd.options.display.max_colwidth = 100  #Set Max col width")
return
Py_Pandas_Options_Max_Col:
ClipProcess("pd.options.display.max_columns = 10  #None =no max cols 0=Autodetect")
return
Py_Pandas_Options_Max_Rows:
ClipProcess("pd.options.display.max_rows = 50  #Max number of rows")
return
Py_Pandas_Options_Expand_Frame:
ClipProcess("pd.options.display.expand_frame_repr = False  #show DataFrame across multiple lines")
return
Py_Pandas_Options_Precision:
ClipProcess("pd.options.display.precision = 4  #Control decimals")
return
Py_Pandas_Options_ColHead_Justify:
ClipProcess("pd.options.display.colheader_justify = 'left' #left right justify header")
return
Py_Pandas_Options_Encoding:
ClipProcess("pd.options.display.encoding = 'UTF-8' #this is default so prob not needed")
return
;**********************data frame*********************************
Py_Pandas_DataFrame_Col_Select:
ClipProcess("mydf=df[['MyCols 1','MyCols 2','MyCols 3']][0:14]  #Select columns and first 15 rows")
Return

Py_Pandas_DataFrame_Col_Count:
ClipProcess("df['MyCol 1'].value_counts()  #Count of items- use max row to expand")
return

Py_Pandas_DataFrame_Col_Filter_Single:
ClipProcess("myFiltered=df['MyCol'] == 'My Value'  #filter single column on value")
return

Py_Pandas_DataFrame_Col_Filter_Multiple:
ClipProcess("MyFilter_1 = df['MyVar 1'] == 'MyVal 1'  #Filter 1`rMyFilter_2 = df['MyVar 2'] == 'MyVal 2'  #Filter 2`rMyFilterd_All_Cols = df[MyFilter_1 & MyFilter_2][:99] #2 filters, all cols, 99 rows`rMyFilterd_Spc_Cols = df[MyFilter_1 & MyFilter_2][['MyVar 1','MyVar 2','MyVar 3']][:99]  #2 filters, spec cols, 99 rows")
return

;**********************Pandas- Graph*********************************
Py_Pandas_Graph_Graph_Necess:
ClipProcess("import matplotlib.pyplot as plot  #Necessary to add so plot will show up`nplot.show()")
Return

;**********************Convert Var*********************************
Py_Convert_To_Integer:
ClipProcess("MyVar = int(MyVar)  # Converts string to Integer. Use w/o 'MyVar =' if you don't need to change original variable")
return

Py_Convert_To_String:
ClipProcess("MyVar = str(MyVar)  # Converts to string. Use w/o 'MyVar =' if you don't need to change original variable")
return

Py_Convert_To_Float:
ClipProcess("MyVar = float(MyVar)  # Converts to float. Use w/o 'MyVar =' if you don't need to change original variable")
return

Py_Convert_List_to_Tuple:
ClipProcess("MyList=list(MyTuple)  #re-casting tuple to list")
Return

Py_Convert_Tuple_To_List:
ClipProcess("MyTuple=tuple(MyList)  #re-casting list to tuple")
return

;**********************Tools / Utilities*********************************
Py_Tools_Utils_Print:
ClipProcess("def p(arg,title=''):  #My Print Function`r`tprint('<<<---START------'+str(title)+'------>>>r'+str(arg)+'r<<<---END------'+str(title)+'--->>>rr')")
return

Py_Tools_Utils_Date_Time:
ClipProcess("import datetime `; print('Today is: {0:%a %b %d %H:%M:%S %Y}'.format(datetime.datetime.now()))")
return

Py_Tools_Utils_iPython:
ClipProcess("import os `; os.system('ipython notebook')  #Display help in HTML")
return


;~ ClipProcess("")
;**************ClipProcess function*********************************
ClipProcess(TXT){
TXT.="`r`n`r`n"
Store:=Clipboard
Clipboard:=TXT
Send, ^v
Sleep, 60
Clipboard:=Store
}
RAlt::
Browser_Forward::Reload

There are other tools for debugging Python but this is a good starting place.

AutoHotKey GUI menu for 17 API calls to web service- Simplify Connecting to amazing SilverPop via API

AutoHotkey GUI menu for API web service

AutoHotkey GUI menu for API web service

For years we have relied on using a browser for interacting with our client (SilverPop) servers.  I had heard that SilverPop had an API for doing much of the same thing but was always “too busy” to take the time to investigate.  At some point I started playing with it and was amazed at how much time could be saved.  After you get passed the “hand-shake” between your computer and the server, the rest is pretty easy.  You simply pass XML to tell the remote servers what action you want to achieve.

I then created an AutoHotKey GUI menu for API web service  which streamlined submitting the XML.

 

Here is the script for AutoHotkey GUI menu for API web service

 
#SingleInstance, Force 
SplitPath,A_ahkPath,,Root
IniRead, RU,%A_MyDocuments%\fdsd.txt, Engage, RU ;gets Username
IniRead, DP,%A_MyDocuments%\fdfds.txt, Engage, DP ;Gets password

;***********************ADD Menu********************************.
Menu, Add_MU_0,Add, Add Contact to Contact List, Add_Contact_to_contact_List_TL
Menu, Add_MU_0,Add, Create Contact List, Add_Create_Contact_List_TL
Menu, Add_MU_0,Add, Import List, Add_Import_List_TL
Menu, Add_MU_0,Add, Opt-out email address, Add_Opt_Out_Recipient_TL

;***********************EXPORT MENU********************************.
Menu, Export_MU_0,Add, Get Aggregate Tracking for &Mailing, Export_Get_Aggregate_Tracking_For_Mailing_TL
Menu, Export_MU_0,Add, Get Aggregate Tracking for &User, Export_Get_Aggregate_Tracking_For_User_TL
Menu, Export_MU_0,Add, Get Aggregate Tracking for &Org, Export_Get_Aggregate_Tracking_For_Org_TL
Menu, Export_MU_0,Add, Get Aggregate Tracking for &Org with Top Domains, Export_Get_Aggregate_Tracking_For_Org_With_Top_Domains_TL
Menu, Export_MU_0,Add, 
Menu, Export_MU_0,Add, Export List, Export_List_TL

;***********************Get********************************.
Menu, Get_MU_0, Add, Get Sent Mailings for &Org, Get_Get_Sent_Mailings_For_Org_TL
Menu, Get_MU_0, Add, Get Sent Mailings for &User, Get_Get_Sent_Mailings_For_User_TL
Menu, Get_MU_0, Add, Get &Job Status, Get_Get_Job_status_TL
Menu, Get_MU_0, Add, Get &Recipient Data, Get_Select_Recipient_Data_TL

;***********************Misc********************************.
Menu, Misc_MU_0, Add, Add others here, Misc_Temp_TL

;***********************Main menu********************************.
Menu, MainMenu, Add, &Add, :Add_MU_0
Menu, MainMenu, Add, &Export, :Export_MU_0
Menu, MainMenu, Add, &Get, :Get_MU_0
Menu, MainMenu, Add
Menu, MainMenu, Add, &Misc, :Misc_MU_0
return
Browser_Forward::Reload
Browser_Back::
^t::Menu, MainMenu, Show  ; right mouse and windows

;***********************Add********************************.
Add_Contact_to_Contact_List_TL:
GoSub Grab_Contact_List_ID
GoSub Grab_Contact_ID
XMLFunc(xml:="<AddContactToContactList><CONTACT_LIST_ID>" . Contact_List_ID . "</CONTACT_LIST_ID><CONTACT_ID>" . Contact_ID . "</CONTACT_ID></AddContactToContactList>")
GoSub Evaluator
Return

Add_Create_Contact_List_TL:
GoSub Grab_Contact_List_Name
XMLFunc(xml:="<CreateContactList><DATABASE_ID>4324324</DATABASE_ID><CONTACT_LIST_NAME>" . Contact_List_Name . "</CONTACT_LIST_NAME><VISIBILITY>1</VISIBILITY></CreateContactList>")
RegExMatch(Response, "<CONTACT_LIST_ID>(\d{7,9})</CONTACT_LIST_ID>", List_ID) ;List_ID1 is Contact List
MsgBox % List_ID1 " is Contact list ID loaded", , 4
Return

Add_Import_List_TL:
GoSub Grab_Map_And_SourceFile
XMLFunc(xml:="<ImportList><MAP_FILE>" . Map_File . "</MAP_FILE><SOURCE_FILE>" . Source_File . "</SOURCE_FILE></ImportList>")
Return

Add_Opt_Out_Recipient_TL:
GoSub Grab_eMail
XMLFunc(xml:="<OptOutRecipient><LIST_ID>43243243</LIST_ID><EMAIL>" . eMail . "</EMAIL></OptOutRecipient>")
GoSub Evaluator

Return

Add_Create_Query_TL:
XMLFunc(xml:="<CreateQuery><QUERY_NAME>Has_Mobile_30_Zip</QUERY_NAME><PARENT_LIST_ID>432432</PARENT_LIST_ID><VISIBILITY>0</VISIBILITY><PARENT_FOLDER_ID>34243</PARENT_FOLDER_ID><ALLOW_FIELD_CHANGE>0</ALLOW_FIELD_CHANGE><SELECT_COLUMNS>Last_Name|First_Name</SELECT_COLUMNS><CRITERIA><TYPE>editable</TYPE><EXPRESSION><TYPE>TE</TYPE><COLUMN_NAME>Zip</COLUMN_NAME><OPERATORS><![CDATA[BETWEEN]]></OPERATORS><VALUES><![CDATA[30000|30999]]></VALUES><LEFT_PARENS>(</LEFT_PARENS></EXPRESSION><EXPRESSION><AND_OR>AND</AND_OR><TYPE>TE</TYPE><COLUMN_NAME>Mobile</COLUMN_NAME><OPERATORS><![CDATA[IS NOT null]]></OPERATORS><RIGHT_PARENS>)</RIGHT_PARENS></EXPRESSION></CRITERIA><BEHAVIOR><OPTION_OPERATOR>103</OPTION_OPERATOR><TYPE_OPERATOR>111</TYPE_OPERATOR><MAILING_ID>669614</MAILING_ID><REPORT_ID>502993</REPORT_ID></BEHAVIOR></CreateQuery>")
return

Add_Create_Table_TL:
XMLFunc(xml:="<CreateTable><TABLE_NAME>Purchases</TABLE_NAME><COLUMNS><COLUMN><NAME>Record Id</NAME><TYPE>NUMERIC</TYPE><IS_REQUIRED>true</IS_REQUIRED><KEY_COLUMN>true</KEY_COLUMN></COLUMN><COLUMN><NAME>Purchase Date</NAME><TYPE>DATE</TYPE><IS_REQUIRED>true</IS_REQUIRED></COLUMN><COLUMN><NAME>Product Id</NAME><TYPE>NUMERIC</TYPE><IS_REQUIRED>true</IS_REQUIRED></COLUMN></COLUMNS></CreateTable>")
Return

;*******************************************************.
;***********************Export********************************.
;*******************************************************.
Export_Get_Aggregate_Tracking_For_Mailing_TL:
gosub Grab_Mailing_ID
gosub Grab_Report_ID
XMLFunc(xml:="<GetAggregateTrackingForMailing><MAILING_ID>" . Mailing_ID . "</MAILING_ID><REPORT_ID>" . Report_ID . "</REPORT_ID></GetAggregateTrackingForMailing>")
return

Export_Get_Aggregate_Tracking_For_Org_TL:
Gosub Grab_Date
XMLFunc(xml:="<GetAggregateTrackingForOrg><DATE_START>" . Date_Start . "</DATE_START><DATE_END>" . Date_End . "</DATE_END><EXCLUDE_TEST_MAILINGS/></GetAggregateTrackingForOrg>")
GoSub ImportExcel
DropUnwantedColumns(Values:="NumSeeds,NumInboxMonitored,NumUniqueAttach,NumGrossAttach,NumUniqueClickstreams,NumGrossClickstreams,NumUniqueMedia,NumGrossMedia,NumGrossAbuse,NumGrossChangeAddress,NumGrossMailRestriction,NumGrossOther,NumConversions,NumConversionAmount,NumBounceHardFwd,NumBounceSoftFwd,NumConversionAmountFwd,NumAttachOpenFwd,NumClickFwd,NumUniqueForwardFwd,NumGrossForwardFwd,NumUniqueConversionsFwd,NumGrossConversionsFwd,NumUniqueClickstreamFwd,NumGrossClickstreamFwd,NumUniqueClickFwd,NumGrossClickFwd,NumUniqueAttachOpenFwd,NumGrossAttachOpenFwd,NumUniqueMediaFwd,NumGrossMediaFwd,NumUniqueOpenFwd,NumGrossOpenFwd,NumAbuseFwd,NumChangeAddressFwd,NumMailRestrictionFwd,NumMailBlockFwd,NumOtherFwd,NumSuppressedFwd")
GoSub DropBlankExcelColumns
GoSub SaveExcel
Return

Export_Get_Aggregate_Tracking_For_Org_With_Top_Domains_TL:
Gosub Grab_Date
XMLFunc(xml:="<GetAggregateTrackingForOrg><DATE_START>" . Date_Start . "</DATE_START><DATE_END>" . Date_End . "</DATE_END><EXCLUDE_TEST_MAILINGS/><TOP_DOMAIN/></GetAggregateTrackingForOrg>")
GoSub ImportExcel
DropUnwantedColumns(Values:="NumSeeds,NumInboxMonitored,NumUniqueAttach,NumGrossAttach,NumUniqueClickstreams,NumGrossClickstreams,NumUniqueMedia,NumGrossMedia,NumGrossAbuse,NumGrossChangeAddress,NumGrossMailRestriction,NumGrossOther,NumConversions,NumConversionAmount,NumBounceHardFwd,NumBounceSoftFwd,NumConversionAmountFwd,NumAttachOpenFwd,NumClickFwd,NumUniqueForwardFwd,NumGrossForwardFwd,NumUniqueConversionsFwd,NumGrossConversionsFwd,NumUniqueClickstreamFwd,NumGrossClickstreamFwd,NumUniqueClickFwd,NumGrossClickFwd,NumUniqueAttachOpenFwd,NumGrossAttachOpenFwd,NumUniqueMediaFwd,NumGrossMediaFwd,NumUniqueOpenFwd,NumGrossOpenFwd,NumAbuseFwd,NumChangeAddressFwd,NumMailRestrictionFwd,NumMailBlockFwd,NumOtherFwd,NumSuppressedFwd")

GoSub DropBlankExcelColumns
GoSub SaveExcel
Return

Export_Get_Aggregate_Tracking_For_User_TL:

XMLFunc(xml:="<GetAggregateTrackingForUser><DATE_START>" . Date_Start . "</DATE_START><DATE_END>" . Date_End . "</DATE_END></GetAggregateTrackingForUser>")
Return

Export_List_TL:

XMLFunc(xml:="<ExportList><LIST_ID>" . List_ID . "</LIST_ID><EXPORT_TYPE>ALL</EXPORT_TYPE><EXPORT_FORMAT>CSV</EXPORT_FORMAT><ADD_TO_STORED_FILES/><DATE_START>" . Date_Start . "</DATE_START><DATE_END>" . Date_End . "</DATE_END></ExportList>")
return
;*******************************************************.
;***********************GET********************************.
;*******************************************************.
Get_Get_Report_ID_By_Date_TL:
XMLFunc(xml:="<GetReportIdByDate><MAILING_ID>" . Mailing_ID . "</MAILING_ID><DATE_START>" . Date_Start . "</DATE_START><DATE_END>" . Date_End . "</DATE_END></GetReportIdByDate>")
return

Get_Get_Sent_Mailings_For_Org_TL:
Gosub Grab_Date
XMLFunc(xml:="<GetSentMailingsForOrg><DATE_START>" . Date_Start . "</DATE_START><DATE_END>" . Date_End . "</DATE_END><EXCLUDE_ZERO_SENT/><EXCLUDE_TEST_MAILINGS/></GetSentMailingsForOrg>")
GoSub ImportExcel
GoSub DropBlankExcelColumns
GoSub SaveExcel
return

Get_Get_Sent_Mailings_For_User_TL:

XMLFunc(xml:="<GetSentMailingsForUser><DATE_START>" . Date_Start . "</DATE_START><DATE_END>" . Date_End . "</DATE_END></GetSentMailingsForUser>")
GoSub ImportExcel
GoSub DropBlankExcelColumns
GoSub SaveExcel
return

GetAggregateTrackingForMailing_TL:
GoSub Grab_Mailing_ID
XMLFunc(xml:="<GetAggregateTrackingForMailing><MAILING_ID>" . Mail_ID . "</MAILING_ID><REPORT_ID>" . Report_ID . "</REPORT_ID> </GetAggregateTrackingForMailing>")
GoSub ImportExcel
GoSub DropBlankExcelColumns
GoSub SaveExcel
return

Get_Get_Job_status_TL:
GoSub Grab_Job_ID
XMLFunc(xml:="<GetJobStatus><JOB_ID>" . Job_ID . "</JOB_ID></GetJobStatus>")
Response:=WebRequest.ResponseText
MsgBox % Response
return

Get_Select_Recipient_Data_TL:
gosub Grab_Email
XMLFunc(xml:="<SelectRecipientData><LIST_ID>4324324</LIST_ID><EMAIL>" . email . "</EMAIL></SelectRecipientData>")
GoSub ImportExcel
;***********************Miscellaneous********************************.
Misc_Temp_TL:
return

Add_Update_Recipient_TL:
;add criteria
return




;*******************************************************.
;*******************************************************.
Login:
Pod:=4
URL:="http://api" . Pod . ".silverpop.com/XMLAPI"
Loginxml:="<Envelope><Body><Login><USERNAME>" . RU . "</USERNAME><PASSWORD>" . DP . "</PASSWORD></Login></Body></Envelope>"
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("POST", URL)
WebRequest.SetRequestHeader("Content-Type", "text/xml;charset=UTF-8")
WebRequest.Send(Loginxml)
GoSub Evaluator ;turn this into function and pass user notification
RegExMatch(Response,"jsessionid=(\w+)\<",jid) ;obtain session ID
URL:="http://api" . Pod . ".silverpop.com/XMLAPI;jsessionid=" . JID1
return

SendXML:
XML:="<Envelope><Body>" . XML . "</Body></Envelope>"
Notify("Status","Sending request",4,"TS=10 TM=8 TF=Times New Roman GC_=Yellow SI_=1000")
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("POST", URL)
WebRequest.SetRequestHeader("Content-Type", "text/xml;charset=UTF-8")
Clipboard:=xml ;added for testing 2/1/2013
MsgBox , 0, clipboard now contains, %xml% , 2 ;added for testing
WebRequest.Send(xml)

return

Evaluator:
MsgBox % Response:="<?xml version=""1.0"" encoding=""UTF-8"" ?>`n" . WebRequest.ResponseText
RegExMatch(Response,"<SUCCESS>(\w+)</SUCCESS>",Status)
If (status1!="TRUE"){
	MsgBox,,Fail, XML Send was not Successful
	Exit
	}
   else
   Notify("Status","Receive was Successful",4,"TS=10 TM=8 TF=Times New Roman GC_=Yellow SI_=1000")
Return

Append_CleanXML_Save:
StringReplace, Response, Response, <SUCCESS>TRUE</SUCCESS>,,
Notify("Status","Received info and Saving",2,"TS=10 TM=8 TF=Times New Roman GC_=Yellow SI_=1000")
Path=%A_Scriptdir%\mailing.xml
FileDelete, %Path%
FileAppend, %response%, %path%,Utf-8
Return

;***********************Import to Excel********************************.
ImportExcel:
Notify("Status","Importing file",6,"TS=10 TM=8 TF=Times New Roman GC_=Yellow SI_=1000")
Xls := ComObjCreate("Excel.Application") ;handle
Xls.Visible := True ;by default excel sheets are invisible

Path=%A_Scriptdir%\mailing.xml
Xls := Xls.Workbooks.OpenXML("B:\Progs\AutoHotkey_L\TI\Engage\API\mailing.xml", 1, 2) ;.LoadOption.2 ;import xml file
xls.activesheet.Name := "Data"
xls:=Excel_Get()
Xls.ActiveSheet.ListObjects("Table1").TableStyle := "TableStyleLight1" ; "" clears formatting
return



SaveExcel:
xls.DisplayAlerts := false ;doesn't ask if I care about overwriting the file
Today := A_MMM . " " . A_DD . ", " . A_YYYY
File := A_ScriptDir . "\Mailings.xlsx"
File := A_ScriptDir . "\Mailings " . Today . ".xlsx"
xls.ActiveWorkbook.Saveas(File, 51) ; 6=csv 51=2007 56=2003
xls.DisplayAlerts := true ;Turn back on warnings
return

DropBlankExcelColumns:
xls:=Excel_Get()
LR := xls.ActiveSheet.UsedRange.Rows.Count ;Last Row
LC := xls.ActiveSheet.UsedRange.Columns.Count ;Grabs last Column
Loop, %LC%
{
CL:=ColtoChar(LC-A_Index+1)
Max:=XLs.Max(xls.Range(CL . "2:" . CL . LR))
Text:=XLs.Range(CL . "2").Value ;
If (Max=0) AND (Text=0) OR (Text=""){
;	MsgBox % max " text " Text " in col " CL
	xls.Range(CL . ":" CL).Delete
	}
}
return

;*******************************************************.
;*******GUI menu for API web service****************GUIS********************************.
;*******************************************************.
Grab_Contact_ID:
RegExMatch(clipboard, "(\d){10}", Contact_ID) ;going to try and extract up to first line
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , What is the Contact ID?
Gui, Add, edit, r1 vContact_ID, %Contact_ID%
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
return

Grab_Contact_List_ID:
RegExMatch(clipboard, "(\d){7}", Contact_List_ID) ;going to try and extract up to first line
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , What is the Contact List ID?
Gui, Add, edit, r1 vContact_List_ID, %Contact_List_ID%
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
return

Grab_Contact_List_Name:
RegExMatch(clipboard, "(\d){8}", Contact_List_Name) ;going to try and extract up to first line
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , What is the Contact List Name?
Gui, Add, edit, r1 vContact_List_Name, %Contact_List_Name%
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
return

Grab_Database_ID:
RegExMatch(clipboard, "(\d){8}", Database_ID) ;going to try and extract up to first line
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , What is the eMail address?
Gui, Add, edit, r1 vDatabase_ID, %Database_ID%
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
Return

Grab_Date:
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , Please select the start time
Gui, Add, DateTime, vDate_Start ;, LongDate
gui, add, text, , `nNow select the end time
Gui, Add, DateTime, vDate_End ;, LongDate
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
Date_Start:= RegExReplace(Date_Start,"(\d\d\d\d)(\d\d)(\d\d).*","$2/$3/$1 00:00:00")
Date_End:= RegExReplace(Date_End,"(\d\d\d\d)(\d\d)(\d\d).*","$2/$3/$1 23:59:59")
return

Grab_Email:
RegExMatch(Clipboard, "\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", eMail)
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , What is the eMail address?
Gui, Add, edit, r1 veMail, %eMail%
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
return

Grab_Job_ID:
RegExMatch(clipboard, "(\d){8}", Job_ID) ;going to try and extract up to first line
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , What is the job ID?
Gui, Add, edit, r1 vJob_ID, %Job_ID% ;, MailID
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
return

Grab_List_ID:
RegExMatch(clipboard, "(\d){8}", List_ID) ;going to try and extract up to first line
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , What is the List ID?
Gui, Add, edit, r1 vList_ID, %List_ID% ;
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
return

Grab_Mailing_ID:
RegExMatch(clipboard, "(\d){8}", Mail_ID) ;going to try and extract up to first line
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , What is the Mail ID?
Gui, Add, edit, r1 vMail_ID, %Mail_ID% ;, MailID
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
return

Grab_Map_And_SourceFile:
RegExMatch(clipboard, "(\S+\.xml)", Map_File) ;filename ending in xml
RegExMatch(clipboard, "(\S+\.csv)", Source_File) ;filename ending in CSV or TXT
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
Gui, Add, text, , What is the name of the Map File?
Gui, Add, edit, r1 Lowercase w150 vMap_File, %Map_File%
Gui, Add, text, , `nWhat is the name of the Source File?
Gui, Add, edit, r1 Lowercase w150 vSource_File, %Source_File%
Gui, Add, Button, Default, OK
Gui, Show, w200
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
return


Grab_Report_ID:
RegExMatch(clipboard, "(\d){9}", Report_ID) ;going to try and extract up to first line
Gui, +AlwaysOnTop -MaximizeBox -MinimizeBox
gui, add, text, , `nWhat is the Report ID?
Gui, Add, edit, r1 vReport_ID, %Report_ID% ;, LongDate
Gui, Add, Button, Default, OK
Gui, Show
Gui +LastFound ;use this in conjunction with next line to have ahk wait for input before proceeding
WinWaitClose
return

ButtonOK:
gui, Submit
Gui, Destroy
return

;***********************Functions********************************.
XMLFunc(XML=""){
gosub Login
gosub SendXML
GoSub Evaluator
GoSub Append_CleanXML_Save
}

ColToChar(index) { ;Converting Columns to Numeric for Excel
	If(index <= 26)
	{
		return Chr(64+index)
	}
	Else If (index > 26)
	{
		return Chr((index-1)/26+64) . Chr(mod((index - 1),26)+65)
	}
}
DropUnwantedColumns(Values=""){
xls:=Excel_Get()
LC := xls.ActiveSheet.UsedRange.Columns.Count ;Grabs last Column
CL:=ColtoChar(LC-A_Index+1)

Loop, %LC%
{
	Header:=xls.Range(CL . "1").Value
	;~ MsgBox % Header
	Loop, parse, Values, `,
	{
		If (Header=A_LoopField)
			xls.Range(CL . ":" CL).Delete
	}
CL:=ColtoChar(LC-A_Index+1)
}
}

 

How to use SciTE messages to control SciTE with AutoHotkey | 63 Extremely powerful messages to control SciTE

How to use SciTE messages

How to use SciTE messages

SciTE is a great IDE that I use with AutoHotKey, SPSS, SQL, Python, XML, HTML, etc.   I love being able to use regular expressions in it to manipulate text and it has some very cool capabilities.  This video is one of my favorite demonstrations how powerful SciTE can be at manipulating text.

Here is a short tutorial and demonstration on how to manipulate SciTE editor via COM objects and Windows commands with AutoHotKey.

Tutorial How to use SciTE messages with AutoHotkey

How to customize SciTE

See the list of SciTE commands here

Take a deep-dive into Scintilla documentation

Look at the Director Interface options

To send messages in AutoHotkey review MSDN

FYI- 0x111 is the WM_COMMAND

SciTE Messages for use in AutoHotkey with a COM object

You can use spy to find wm_command

A specific version of the SciTE editor for AutoHotKey can be downloaded here and more generic documentation can be found here.

AutoHotKey Menu Builder- save hours of time by streamlining menu creation

AutoHotKey menu builderAHK is simple enough for me, an non-programmer, to program in however their GUIs are very tricky.  I wrote an AutoHotKey menu builder to help automate the building of them.  This can save a lot of time when trying to build menus.

Just remember that sub-menus need to be placed above their parents!  This always confused me because I wanted to put them below their parent’s .  You can also review this video which helps educate you on some of the built in features of AHK to control GUI placement

AutoHotKey Menu Builder