Jump to content

User:Ikip/script

From Wikipedia, the free encyclopedia
My Documents\autohotkey\lib (create both folders first)

Both files we have created are confusingly the same file name.

rum.ahk: place in My documents

[edit]
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance Force	; prevents dialogue with forceful restart

OnMessage(0x44, "WM_COMMNOTIFY")	; provides for a graceful reload when app exit subs take some time before closing the app

AutoTrim on
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetFormat, Integer, d
DetectHiddenText, off
DetectHiddenWindows, off
SetKeyDelay, 0, 0		; set delay for virtual keystrokes
SetControlDelay, 0
SetTitleMatchMode, 2	; match beginning mode
OnExit, rum_Exit_app

Rum_Start_app()	; init code and what not

; wiki_del_repo_url := rum_query_user_for_article_repo()	;returns the repo url entered by the user
wiki_del_repo_url := "http://en.wikipedia.org/wiki/User:Ikip/77" ; hard coded for the time being

wiki_article_del_cnt := rum_article_get_del_cnt(wiki_del_repo_url)	; returns article count - also builds an array of article titles > wiki_article%element% where element 0 = total article count

final_results := "'''Total number of articles up for deletion review''': " . wiki_article_del_cnt
				. "`n__TOC__`n"

loop, %wiki_article_del_cnt%
	{
	wiki_article_num := a_index
	
	wiki_article_GNEWS_hits%a_index%  := rum_article_get_GNEWS_hits(wiki_article%a_index%, a_index)	; returns the gnews hit counts on the article - passing indes for file naming purposes
	wiki_article_GBOOK_hits%a_index%  := rum_article_get_GBOOK_hits(wiki_article%a_index%, a_index)	; returns the gbook hit counts on the article - passing indes for file naming purposes
	wiki_article_GSCHOLAR_hits%a_index%  := rum_article_get_GSCHOLAR_hits(wiki_article%a_index%, a_index)	; my try
	wiki_article_edit_count%a_index%  := rum_article_get_editor_cnt(wiki_article%a_index%, a_index)	; returns the editor count on the article - passing indes for file naming purposes

	wiki_article_CREATOR%a_index%  := rum_article_get_CREATOR(wiki_article%a_index%, a_index)	; returns the article's creator
	wiki_article_NOMINATOR%a_index%  := rum_article_get_NOMINATOR(wiki_article%a_index%, a_index)	; returns article's deletion nominator

	editor_vitals :=
	loop, % wiki_article_edit_count%wiki_article_num% 	;%
		{
		editor_vitals .= "<!--name-->[http://en.wikipedia.org/w/index.php?title=User_talk:{{urlencode:" . Wiki_Art_%wiki_article_num%_Editor_%a_index%_Name . "}}&action=edit&section=new&preloadtitle={{urlencode:[[" . wiki_article%wiki_article_num% . "]] which you contributed to, is currently up for [[Wikipedia:Articles_for_deletion/" . wiki_article%wiki_article_num% . "|deletion]]}}&preload=User:ikip/7 " . Wiki_Art_%wiki_article_num%_Editor_%a_index%_Name . "] "
		editor_vitals .= Wiki_Art_%wiki_article_num%_Editor_%a_index%_EditCounts . " "
		editor_vitals .= Wiki_Art_%wiki_article_num%_Editor_%a_index%_LastEditDate . " "
}

final_results .= "`n{|style=""border: solid 2px #D72323; padding: 8px;""`n|valign=top align=center style=""background-color:#F3F2F2""|[[Wikipedia:Articles_for_deletion/" . wiki_article%a_index% . "|" . wiki_article%a_index% . "]]<!--1 of …-->`n" . a_index . " of " . wiki_article_del_cnt
			. "`n|valign=top align=center|'''Google'''`n{|`n|`n|valign=top align=center|'''News'''`n<span class=""plainlinks""> [http://news.google.com/archivesearch?q={{urlencode:""" . wiki_article%a_index% . """}} " . wiki_article_GNEWS_hits%a_index% 	. "]`n|valign=top align=center|'''Books'''`n<span class=""plainlinks"">[http://books.google.com/books?q=%2B{{urlencode:""" . wiki_article%a_index% . """}} " . wiki_article_GBOOK_hits%a_index% . "]`n|valign=top align=center|'''Scholar'''`n<span class=""plainlinks"">[http://scholar.google.com/scholar?&q={{urlencode:""" . wiki_article%a_index% . """}} " . wiki_article_Gscholar_hits%a_index% . "]`n|}`n{{{!}} <!-- Template:Collapse top --> class=""navbox collapsible {{#if:||collapsed}}"" style=""text-align: left; border: 1px solid silver; margin-top: 0.2em;""`n{{!}}-`n! style=""background-color: #F3F2F2;"" {{!}} cut and paste    `n{{!}}-`n{{!}} style=""border: solid 1px silver; padding: 8px; background-color: white; "" {{!}}`nGoogle news: [http://news.google.com/archivesearch?q={{urlencode:""" . wiki_article%wiki_article_num% . """}} " . wiki_article_GNEWS_hits%a_index% . "],   Google books: [http://books.google.com/books?q=%2B{{urlencode:""" . wiki_article%wiki_article_num% . """}} " . wiki_article_GBOOK_hits%a_index% . "],  Google scholar: [http://scholar.google.com/scholar?&q={{urlencode:""" . wiki_article%wiki_article_num% . """}} " . wiki_article_Gscholar_hits%a_index% . "]`n{{collapse bottom}}`n|valign=top|'''Editor Count:''' " . wiki_article_edit_count%a_index% . " '''Creator:''' " . wiki_article_CREATOR%a_index% . " '''Nominator:''' " . wiki_article_NOMINATOR%a_index% . "`n<!--1st name--><span class=""plainlinks"">" 
			. editor_vitals ; all editor statistics
			. "</span>`n<div style=""font-size:70%; text-align:right"">[[File:Life Preserver.svg|15px]] Brought to you by the [[WP:ARS|Article Rescue Squadron]]</div>`n|}`n{{Wikipedia:Articles_for_deletion/" . wiki_article%a_index% . "|" . wiki_article%a_index% . "}}`n "

	}


; rum_display_results()

filedelete, resources\final_results.txt
fileappend, %final_results%, resources\final_results.txt
; msgbox %errorlevel% 

Run, notepad.exe "%A_WorkingDir%\resources\final_results.txt"
; Run, resources\final_results.txt
goto Rum_Exit_app

Return

rum.ahk in My Documents\autohotkey\lib

[edit]
;------------------------------------------------------------------------------------------
WM_COMMNOTIFY(wParam) {
	global
	If (wParam = 1031) ; AHK_Exit_BY_SingleINSTANCE
		MsgBox, 0,, Exiting to make way for another instance!, 1
	}
;------------------------------------------------------------------------------------------
Rum_Start_app() {
	global
	If !FileExist(A_ScriptDir . "\resources")
		FileCreateDir, % A_ScriptDir . "\resources"		;%
	else
		FileRecycle, resources\*.*
	COM_Init()
	Return
	}
;------------------------------------------------------------------------------------------
Rum_Exit_app: ;**
	Sleep 1000
	COM_Term()
	ExitApp  ; The only way for an OnExit script to terminate itself is to use ExitApp in the OnExit subroutine
Return ;*
;------------------------------------------------------------------------------------------
Rum_Reload_app() {
	global
	Reload
	Return
	}
;------------------------------------------------------------------------------------------
rum_article_get_del_cnt(wiki_del_repo)	{ ; ROLLED OVER TO COM returns article count - also builds an array of article titles > wiki_article%element% where element 0 = total count
	global
	
	URLDownloadToFile, %wiki_del_repo%, resources\wiki.htm
	FileRead, WIKIPEDIAsource, resources\wiki.htm

	wiki_article0 := 0
	
	doc := COM_CreateObject("{25336920-03F9-11CF-8FD0-00AA00686F13}")
	COM_Invoke(doc, "write", WIKIPEDIAsource)
	COM_Invoke(doc, "Close")
	
	spans := COM_Invoke(doc, "getElementsByTagName", "span")

	span_cnt := COM_Invoke(spans, "length")	;%

	; msgbox, # spans: %span_cnt%

	index_pointer := 0

	Loop, %span_cnt%
		{
		span := COM_Invoke(spans, "item", A_Index-1)

		If COM_Invoke(span, "className")="toctext"
			{
			index_pointer++
			content_span_index%index_pointer% := a_index
			}
		COM_Release(span)
		}
		
	content_span_cnt := index_pointer

	index_pointer := 1	; the autogenerated arrays are 1 based, not 0 based - see bottom of loop
	Loop, %span_cnt%
		{
		span := COM_Invoke(spans, "item", A_Index-1)

		If (content_span_index%index_pointer% = a_index)	; <-- this is why i am indexing at 1 vs 0
			{
			If COM_Invoke(span, "className")="toctext"
				{
					temp := COM_Invoke(span, "innerText")
					wiki_article%index_pointer% = %temp%	;stripping off leading and trailing spaces - autotrim is on
				}
			index_pointer++
			}
		COM_Release(span)
		}
	index_pointer--		; get it back in sync 
		
	COM_Release(spans)
	COM_Release(doc)
		
	return, (wiki_article0 := index_pointer)
}
;------------------------------------------------------------------------------------------
rum_article_get_gnews_hits(wiki_article, index="")	{	; THIS WAS NOT ROLLED OVER TO COM - ONLY ADAPTED returns the gnews hit counts on the article
	global
	
	URLDownloadToFile, % "http://news.google.com/archivesearch?q=" . chr(34) . wiki_article . chr(34) . "+&btnG=Search+Archives", resources\GNews%index%.htm	;%
	FileRead, GNEWSsource, resources\GNews%index%.htm
	RegExMatch(GNEWSsource, "of (?:about )?<b>(\S+)</b>", Subl)
	RetVal:= RegExReplace(Subl1, "[^\d]")
	if (RetVal = "")
		RetVal := 0

	return, RetVal
	}
;------------------------------------------------------------------------------------------
rum_article_get_gbook_hits(wiki_article, index="")	{	; THIS WAS NOT ROLLED OVER TO COM - ONLY ADAPTED returns the gbook hit counts on the article
	global
	
	URLDownloadToFile, % "http://books.google.com/books?q=%2B" . chr(34) . wiki_article . chr(34) . "+&btnG=Search+Books", resources\GBooks%index%.htm	;%
	FileRead, GBOOKsource, resources\GBooks%index%.htm
	RegExMatch(GBOOKsource, "of (?:about )?<b>(\S+)</b>", Subn)
	RetVal := RegExReplace(Subn1, "[^\d]")
	if (RetVal = "")
		RetVal := 0

	return, RetVal
	}
;------------------------------------------------------------------------------------------
rum_article_get_CREATOR(wiki_article, index="")	{	; ; THIS IS A COM implementation
	global
	
	; http://en.wikipedia.org/w/index.php?title=BLAHBLAHBLAH&dir=prev&action=history&limit=1
	
	URLDownloadToFile, % "http://en.wikipedia.org/w/index.php?title=" wiki_article . "&dir=prev&action=history&limit=1", resources\CREATOR%index%.htm	;%
	FileRead, CREATORsource, resources\CREATOR%index%.htm

	wiki_CREATOR_0 := 0
	
	doc := COM_CreateObject("{25336920-03F9-11CF-8FD0-00AA00686F13}")
	COM_Invoke(doc, "write", CREATORsource)
	COM_Invoke(doc, "Close")
	
	spans := COM_Invoke(doc, "getElementsByTagName", "span")

	span_cnt := COM_Invoke(spans, "length")

	; msgbox, # spans: %span_cnt%

	index_pointer := 0

	Loop, %span_cnt%
		{
		span := COM_Invoke(spans, "item", A_Index-1)

		If COM_Invoke(span, "className")="history-user"
			{
			index_pointer++
			content_span_index%index_pointer% := a_index
			}
		COM_Release(span)
		}
		
	content_span_cnt := index_pointer

	; msgbox, # of spans with className=history-user: %index_pointer%
	
	index_pointer := 1	; the autogenerated arrays are 1 based, not 0 based - see bottom of loop
	Loop, %span_cnt%
		{
		span := COM_Invoke(spans, "item", A_Index-1)

		If (content_span_index%index_pointer% = a_index)	; <-- this is why i am indexing at 1 vs 0
			{
			If COM_Invoke(span, "className")="history-user"
				{
					a:=COM_Invoke(span, "firstChild")
					temp := COM_Invoke(a, "innerText")
					COM_Release(a)
					wiki_CREATOR_%index_pointer% = %temp%	;stripping off leading and trailing spaces - autotrim is on
				}
			index_pointer++
			}
		COM_Release(span)
		}
	index_pointer--		; get it back in sync 
		
	COM_Release(spans)
	COM_Release(doc)
	
	wiki_CREATOR_0 := index_pointer
	
	return, wiki_CREATOR_1
	}
;------------------------------------------------------------------------------------------
rum_article_get_NOMINATOR(wiki_article, index="")	{	; ; THIS IS A COM implementation
	global
	
	; http://en.wikipedia.org/w/index.php?title=Wikipedia:Articles%20for%20deletion/BLAHBLAHBLAH&dir=prev&action=history&limit=1
	
	URLDownloadToFile, % "http://en.wikipedia.org/w/index.php?title=Wikipedia:Articles%20for%20deletion/" . wiki_article . "&dir=prev&action=history&limit=1", resources\NOMINATOR%index%.htm	;%
	FileRead, NOMINATORsource, resources\NOMINATOR%index%.htm

	wiki_NOMINATOR_0 := 0
	
	doc := COM_CreateObject("{25336920-03F9-11CF-8FD0-00AA00686F13}")
	COM_Invoke(doc, "write", NOMINATORsource)
	COM_Invoke(doc, "Close")
	
	spans := COM_Invoke(doc, "getElementsByTagName", "span")

	span_cnt := COM_Invoke(spans, "length")

	; msgbox, # spans: %span_cnt%

	index_pointer := 0

	Loop, %span_cnt%
		{
		span := COM_Invoke(spans, "item", A_Index-1)

		If COM_Invoke(span, "className")="history-user"
			{
			index_pointer++
			content_span_index%index_pointer% := a_index
			}
		COM_Release(span)
		}
		
	content_span_cnt := index_pointer

	; msgbox, # of spans with className=history-user: %index_pointer%
	
	index_pointer := 1	; the autogenerated arrays are 1 based, not 0 based - see bottom of loop
	Loop, %span_cnt%
		{
		span := COM_Invoke(spans, "item", A_Index-1)

		If (content_span_index%index_pointer% = a_index)	; <-- this is why i am indexing at 1 vs 0
			{
			If COM_Invoke(span, "className")="history-user"
				{
					a:=COM_Invoke(span, "firstChild")
					temp := COM_Invoke(a, "innerText")
					COM_Release(a)
					wiki_NOMINATOR_%index_pointer% = %temp%	;stripping off leading and trailing spaces - autotrim is on
				}
			index_pointer++
			}
		COM_Release(span)
		}
	index_pointer--		; get it back in sync 
		
	COM_Release(spans)
	COM_Release(doc)
	
	wiki_NOMINATOR_0 := index_pointer
	
	return, wiki_NOMINATOR_1
	}
;------------------------------------------------------------------------------------------
rum_article_get_gscholar_hits(wiki_article, index="")	{	; THIS WAS NOT ROLLED OVER TO COM - ONLY ADAPTED my try GScholar
	global
	
	URLDownloadToFile, % "http://scholar.google.com/scholar?q=" . chr(34) . wiki_article . chr(34) . "&hl=en&btnG=Search", resources\GScholar%index%.htm	;%
	FileRead, GSCHOLARsource, resources\GSCHOLAR%index%.htm
	RegExMatch(GSCHOLARsource, "of (?:about )?<b>(\S+)</b>", Subq)
	RetVal := RegExReplace(Subq1, "[^\d]")
	if (RetVal = "")
		RetVal := 0

	return, RetVal
	}
;------------------------------------------------------------------------------------------
rum_article_get_editor_cnt(wiki_article, index="")	{	; ROLLED OVER TO COM returns the editor count on the article and builds the editor arrays
	global												; Wiki_Art_%#%_editor_%element%, where Wiki_Art_%#%_editor_0 = total editor count for article %#%

	URLDownloadToFile, % "http://toolserver.org/~daniel/WikiSense/Contributors.php?wikilang=en&wikifam=.wikipedia.org&grouped=on&page=" . wiki_article . "", resources\WikiEditors%index%.htm	;%
	FileRead, WikiEditorSource, resources\WikiEditors%index%.htm

	Wiki_Editor_Cnt0 := 0
	
	doc := COM_CreateObject("{25336920-03F9-11CF-8FD0-00AA00686F13}")
	COM_Invoke(doc, "write", WikiEditorSource)
	COM_Invoke(doc, "Close")
	
	tables  := COM_Invoke(doc, "getElementsByTagName", "table")
	table_cnt := COM_Invoke(tables, "length")	;%
	
	Loop, %table_cnt%   ; TO GRAB ALL tables, but should only be ONE
		{
		t := COM_Invoke(tables, "item", A_Index-1)
		WikiEditorTable%a_index% := COM_Invoke(t, "innerText")
		COM_Release(t)
		}

	COM_Release(tables)
	COM_Release(doc)
	
	; all editor vitas should now be in WikiEditorTableX  now need to build individual arrays
	
	Loop, %table_cnt%	; TO GRAB ALL tables, but should only be ONE
		{
		filedelete, resources\Editor_Vitals_%index%_%a_index%.txt
		fileappendstring := WikiEditorTable%a_index%
		fileappend, %fileappendstring%, resources\Editor_Vitals_%index%_%a_index%.txt

		loop, read, resources\Editor_Vitals_%index%_%a_index%.txt
			{
			editor_index := a_index - 1
			if (a_index = 1)
				continue		; first line has column headers from table
			
			test := InStr(A_LoopReadLine, ")")	; Returns the position of the first occurrence 
			name_len := strlen(A_LoopReadLine) - test - 32
			
			StringRight, EditDates, A_LoopReadLine, 32	; 2007-11-28 20:482007-11-28 20:51
			StringRight, lastEditDatetime, EditDates, 16	; 2007-11-28 20:51
			Stringleft, Wiki_Art_%index%_Editor_%editor_index%_LastEditDate, lastEditDatetime, 10	; 2007-11-28
			
			stringleft, Wiki_Art_%index%_Editor_%editor_index%_EditCounts, A_LoopReadLine, test

			Wiki_Art_%index%_Editor_%editor_index%_Name := substr(A_LoopReadLine, (test +1), name_len)
			
			}
		}
		
	return, (Wiki_Editor_Cnt0 := editor_index)
	}
;------------------------------------------------------------------------------------------
rum_display_results()	{
	global
	
	return
	}
;------------------------------------------------------------------------------------------

Create a resources folder in my documents

[edit]

Create a resources folder in my documents.