06: Chrome and AutoHotkey: Getting lists from page

Automating and ChromeHere we continue with GeekDude working with Chrome and AutoHotkey extracting data from a webpage.  This session we focus on getting lists and leverage JSON, Chrome.Jxon_Dump, JSON.stringify, Chrome.Jxon_Load and jQuery.

The great news is that GeekDude explained how we can see the Reddit site the way it was the below video!

By logging into https://old.reddit.com/r/AutoHotkey/, the HTML will be the same as in the video!

Chrome and AutoHotkey: Getting lists from page

donate to GeekDudeIf you’re loving this, please consider donating to GeekDude!

Notes: Chrome and AutoHotkey: Getting lists from page

00:05     Sometimes you want multiple items from a page.  Maybe all post titles, or all links form comments.

00:20     Looking in HTML we see there’s a lot going on.  We need to look at the structure BEFORE we get working on it.

Continue reading

Easily pushing delimited data into a ListView in AutoHotkey

I used to be a Data Scientist and often found data that I’d want to “peak” at.  AutoHotkey listviews are an easy way to do this!

Example Easily pushing delimited data into a ListView in AutoHotkey

https://youtu.be/XdHqE6v4Ov8

Here’s the code I used to Easily pushing delimited data into a ListView in AutoHotkey
 


#Include  
;**************************************
Data=
(
Email First_Name Last_Name Title Another more more2
[email protected] Joe Glines the-Automator LastFound one End
[email protected] Jon King King big guy Here
[email protected] Joseph GLines Something now what ok
)

Data1=
(
ONE,TWO,THREE,FOUR,FIVE,SIX
1one,1two,1three,1four,1five,1six
2one,2two,2three,2four,2five,2six
)
LV_Table(Data1,",",1,Title:="Example Tab delimited data & not using header") ;comma on variable
;~ Data_Source3:=A_ScriptDir . "\data.txt"
;~ LV_Table(Data_Source3,,0,Title:="Example large tab delimited FILE not using header") ;tab on file

;~ LV_Table(Post, delimiter:="`t",UseHeader:=1,Title:="Joe's posts")
LV_Table(Data_Source, delimiter="`t",UseHeader=1,Title=""){ ; default delimiter set to tab
if FileExist(Data_Source) ;if file exists use it as source
FileRead, Data_Source, %Data_Source% ;read in and store as variable

;***********parse the data in variable and store in object*******************
data_obj := StrSplit(Data_Source,"`n","`r") ;parse earch row and store in object
rowHeader:=StrReplace(data_obj.RemoveAt(1),Delimiter,"|",Numb_Columns) ; Remove header from Object and convert to pipe delimited
if (useHeader=0){
loop, % Numb_Columns+1
RH.="Col_" A_Index "|"
rowHeader:=RH
}

dCols:= (Numb_Columns<8) ? 400: ((Numb_Columns<80) ? 650 : 1100) ;if cols <10 use 400; if cols <80 use 650 ; else use 1100
dRows:= (data_obj.MaxIndex() >27) ? 26 : data_obj.MaxIndex() ;if rows >27 use 26 else use # of rows

Gui, Table_View: New,,%Title% ;create new gui window and set title
Gui, Add, ListView, w%dCols% r%dRows% grid , % rowHeader ;set headers

For Each, Row In data_obj ;add the data lines to the ListView
LV_Add("", StrSplit(Row, Delimiter)*) ;LV_Add is a variadic function

Gui, Table_View:Show
}

How I used Google Translate to save the client both time and money

In this session of “what I’ve automated with AutoHotkey” I explain how I saved my client a ton of time and money by using the Google Translate API.

How I used Google Translate to save the client both time and money

Below is the code I used in the code to Google Translate to save the client both time and money.  Make sure you put my Excel function library and Maestrith’s Notify function in your library.

#SingleInstance,Force
Global API_Key,ID,All,From,To,XL,EndPoint,LangObj
Global Column_to_Translate:="A", Column_To_Put_Translations:="B"
;**************************************
EndPoint:="https://www.googleapis.com/language/translate/v2" ; ?parameters
IniRead, API_Key,Auth.ini,API, Key ;read current token (You'll need to get your own)

XL:=XL_Handle(1)
if ! IsObject(Xl) { ;Joe added 9/22 to make sure Excel is loaded before running
  MsgBox % "Please Start Excel then click this box"
  Reload
}

LangObj:={"Chinese Trad":"zh-CN","Chinese Simp":"zh-TW",Italian:"it",Czech:"cs",French:"fr",German:"de",Hebrew:"he",Indonesian:"id",Japanese:"ja",Korean:"ko",Malay:"ms",Polish:"pl",Portuguese:"pt",Russian:"ru",Spanish:"es",Thai:"th",Turkish:"tr",Vietnamese:"vi",English:"en"}
for a in LangObj ;Build Language object for ComboBox
  LangList.=a "|"

All:=[]
gui,+hwndMain
ID:="ahk_id" Main
gui,Add,ListView,w800 h300,Text
gui,Add,ComboBox,vFrom,% Trim(LangList,"|") ;~ https://cloud.google.com/translate/docs/languages
gui,Add,ComboBox,x+m vTo,en||it|es|la ;Languages to translate into
gui,Add,Text,x+60, Column to be translated 
gui,Add,ComboBox,x+m w50 vColumn_to_Translate,A||B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z  ;Store which column to translate
gui,Add,Text,x+60, Destination for translations
gui,Add,ComboBox,x+m w50 vColumn_To_Put_Translations,A|B||C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z ;Store where to put the translations
gui,Add,Button,xm gLang,Discover Language 
gui,Add,Button,x+25 gTranslate,Translate
gui,Add,Button,xm gRefresh,Refresh
Refresh()
gui,Show
return

Refresh(){
  Rows:=XL.ActiveSheet.UsedRange.Rows.Count,LV_Delete(),All:=[]
  while(A_Index<=Rows){
    if(Value:=(Obj:=XL.Range(Column_to_Translate . A_Index)).Value)
      All.Push(Obj),LV_Add("",Value)
    if(All.MaxIndex()=15)
      Break
  }LV_Modify(1,"Select Vis Focus")
}
Translate(){
  Gui,Submit,NoHide
  From:=LangObj[From]?LangObj[From]:From
  if(!From||!To)
    return m("Both Language values must be set")
  XL.Columns(Column_To_Put_Translations).ColumnWidth:=100
  Rows:=XL.ActiveSheet.UsedRange.Rows.Count
  Blank:=0,BlankInput:=0
  while(A_Index<=Rows){
    if(!(Obj:=XL.Range(Column_To_Put_Translations . A_Index)).Value){
      Blank:=0
      t("Processing")
      if(Value:=XL.Range(Column_to_Translate . A_Index).Value){
        QueryString:=QueryString_Builder({"source":From,"target":To,"q":Value,"key":API_Key})
        RegExMatch(Val:=API_Call(EndPoint,queryString),"OUi)\x22translatedText\x22:\s+\x22(.*)\x22",Found)
        Text:=Found.1
        while(RegExMatch(Text,"OU)(\&#(\d+);)",Found))
          Text:=RegExReplace(Text,"\Q" Found.1 "\E",Chr(Found.2))
        while(RegExMatch(Text,"OU)(\&quot;)",Found))
          Text:=RegExReplace(Text,"\Q&quot;\E",Chr(34))
        Obj.Value:=Text
      }
    }else{
      Blank++
      m(Blank)
      if(Blank=5)
        Break
    }
  }
  t(),Notify(60).AddWindow("Complete",{size:14,Animate:"Center",ShowDelay:1000,Icon:161,IconSize:15,Title:"Translations",TitleSize:14,Color:"0x00FF00",TitleColor:"0xFF0000",time:6000})
}
GuiEscape:
GuiClose:
ExitApp
return
;********************Language detection***********************************
Lang(){
  Lang:=API_Call("https://translation.googleapis.com/language/translate/v2/detect",QueryString_Builder({q:All[LV_GetNext()].Value,key:API_Key}))
  RegExMatch(Lang,"OUi)\x22language\x22:\s+\x22(.*)\x22",Found)
  for a,b in LangObj
    if(b=Found.1)
      Language:=a
  ControlSetText,ComboBox1,% Language?Language:Found.1,%ID%
}
;********************API Call***********************************
API_Call(EndPoint,queryString){
  static WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  WebRequest.Open("GET", EndPoint . queryString)
  WebRequest.SetRequestHeader("Accept", "text/xml;charset=UTF-8")
  WebRequest.Send()
  return Response:=WebRequest.ResponseText
}
;********************URI Encode charachters***********************************
UriEncode(Uri, full = 0){
  oSC := ComObjCreate("ScriptControl")
  oSC.Language := "JScript"
  Script := "var Encoded = encodeURIComponent(""" . Uri . """)"
  oSC.ExecuteStatement(Script)
  encoded := oSC.Eval("Encoded")
  Return encoded
}

 

AutoHotkey Webinar- Using AHK string functions in Excel

AHK In this webinar we walked through using AutoHotkey String functions in Excel.

Script Highlight:  Pull data about your computer with WMI by shajul.  Forum post and my link to the zipped files of the separate scripts I wrote

Video Hour 1 & 2 : AHK string functions in Excel

Books on RPA (Robotics Process Automation) that I mentioned in the webinar

Below are links to books I showed during the webinar. I put them into two groups (those I like/recommend and those I don’t). I’m more of a “glass is half-full” kind of guy and think technology is good. The books I don’t recommend were much more negative towards technology. While I don’t recommend them, I think time will tell who is right/wrong.  Personally any of the following you buy I’d try and buy as used.  Many are pretty expensive new (probably because of the small market size)

Recommended Robotics Process Automation books

Service Automation: Robots and the Future of Work 2016 -Great book!
Robotic Process Automation and Risk Mitigation: The Definitive Guide 2017
Robotic Process and Cognitive Automation: The Next Phase 2018 -Great book!
The Singularity Is Near: When Humans Transcend Biology 2019 – very interesting
Life After Google: The Fall of Big Data and the Rise of the Blockchain Economy 2018 – some wild ideas here
The Human Advantage: The Future of American Work in an Age of Smart Machines 2018
The Glass Cage: How Our Computers Are Changing Us 2015
Managing IT as a Strategic Resource 1997
Beyond the IT Productivity Paradox 1999 – old but still interesting

Not recommended but still on the RPA topic

In The Age Of The Smart Machine: The Future Of Work And Power 1989
The Lights in the Tunnel: Automation, Accelerating Technology and the Economy of the Future 2009
A Dangerous Master: How to Keep Technology from Slipping Beyond Our Control 2015
Rise of the Robots: Technology and the Threat of a Jobless Future 2016

 

We also mentioned using ternary operators

and Alternate Data Stream as data storage

Here’s the code Jackie walked through.

#SingleInstance,Force
username := "Jackie"

msgbox % "Name: " username "`nPassword: " password()
return
password(){
  FilePath := A_ScriptFullPath
  IniRead, Var, %FilePath%:Stream:$DATA, Settings, Pass, error
  If (Var="error"){
    InputBox, Var , New, Please enter password, HIDE
    IniWrite, %Var%, %FilePath%:Stream:$DATA, Settings, Pass
  }
  return Var
}