Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.81 KB | None | 0 0
  1. /*
  2.  
  3. Script for regularly checking for new Stack Exchange tag questions and/or new inbox items.
  4.  
  5. This script is obviously only helpful if you have your Windows PC turned on with the script active.
  6.  
  7. (c)2015_03_02 Blauhirn
  8. eochgls@web.de
  9. .___.
  10. {o,o}
  11. /)___)
  12. --"-"--
  13.  
  14. Important: You need to be logged in permanenlty to StackExchange WITHIN INTERNET EXPLORER. Ahk accesses cache from there.
  15.  
  16. One might want to put this script into his/her Windows startup folder
  17. Win7: C:UsersUSERNAMEAppDataRoamingMicrosoftWindowsStart MenuProgramsStartup
  18.  
  19. */
  20.  
  21.  
  22. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. ; USER-DEFINED SECTION
  24.  
  25.  
  26. /*
  27. INTERVALS
  28. between two checks
  29. ENTITY: SECONDS
  30. For no checks at all, state a number <= 0, e.g. -1
  31. */
  32. check_tags_interval = 60
  33. check_inbox_interval = 300
  34.  
  35.  
  36.  
  37. /*
  38. EMAIL
  39. (optional)
  40. state a GOOGLE MAIL account NAME (withOUT the "@gmail.com"-part), if you want to automatically send an E-Mail to yourself when this very ahk-script has got a new notification.
  41. If you do not want to use this feature, leave the account name empty
  42. */
  43. gmail_accountName =
  44. gmail_accountPass =
  45.  
  46.  
  47.  
  48. /*
  49. INBOX
  50. State the link to your Stack Exchange inbox, if you want to use this feature. If not, set check_inbox_interval to -1.
  51. You can get your inbox Link by clicking on the inbox and scrolling to its very bottom
  52. example:
  53. http://stackexchange.com/users/4667026/blauhirn?tab=inbox
  54. */
  55. linkToTheUserprofileInbox =
  56.  
  57.  
  58.  
  59. /*
  60. TAGS
  61. note: you do NOT HAVE TO subscribe to these within StackExchange itself
  62. state Stack Exchange tag sites to check after each check_tags_interval. If you do not want to check for any tags at all, set check_tags_interval to -1.
  63. syntax:
  64. site1 = http://stackoverflow.com/questions/tagged/autohotkey
  65. site2 = http://codereview.stackexchange.com/questions/tagged/java
  66. note: THE SITES HAVE TO BE IN ORDER, STARTING WITH 1
  67. add any tag sites of your preference:
  68. */
  69. site1 = http://stackoverflow.com/questions/tagged/autohotkey
  70. site2 = http://codereview.stackexchange.com/questions/tagged/java
  71.  
  72.  
  73.  
  74.  
  75. ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. ; THE CODE BELOW DOES NOT HAVE TO BE CHANGED
  77.  
  78.  
  79.  
  80. #NoEnv
  81. #persistent
  82. SendMode Input
  83. SetWorkingDir %A_ScriptDir%
  84.  
  85. if(check_tags_interval > 0)
  86. {
  87. loop
  88. {
  89. site_ := site%a_index%
  90. if site_ =
  91. {
  92. if a_index = 1
  93. {
  94. msgbox, You set a timer for tags but did not include any sites to check! Script will exit.
  95. exitapp
  96. }
  97. break
  98. }
  99. else
  100. tmp = §§§K§J§KJ§§J§J§%site_%§§L§L§L§OL§
  101. site%a_index%_short := regExReplace(tmp, "U)§§§K§J§KJ§§J§J§http://(.+)..*§§L§L§L§OL§","$1")
  102. site__short := site%a_index%_short
  103. iniRead, lastNewQuestion_%site__short%, config.ini, %site__short%, lastNewQuestion, default
  104. }
  105. goSub, checkTags
  106. check_tags_interval := check_tags_interval * 1000
  107. setTimer, checkTags, %check_tags_interval%
  108. }
  109. if(check_inbox_interval > 0)
  110. {
  111. iniRead, lastInbox, config.ini, Inbox, lastInbox, default
  112. goSub, checkInbox
  113. check_inbox_interval := check_inbox_interval * 1000
  114. setTimer, checkInbox, %check_inbox_interval%
  115. }
  116.  
  117.  
  118. return
  119.  
  120. ; the following function origins from Sergio @ http://www.autohotkey.com/board/topic/95823-send-email-through-gmail-using-mailsend/
  121. sendMail(emailToAddress,emailPass,emailFromAddress,emailSubject,emailMessage)
  122. {
  123. mailsendlocation := A_MyDocuments
  124. IfNotExist, %mailsendlocation%mailsend1.17b12.exe
  125. URLDownloadToFile, https://mailsend.googlecode.com/files/mailsend1.17b12.exe, %mailsendlocation%mailsend1.17b12.exe
  126. Run, %mailsendlocation%mailsend1.17b12.exe -to %emailToAddress% -from %emailFromAddress% -ssl -smtp smtp.gmail.com -port 465 -sub "%emailSubject%" -M "%emailMessage%" +cc +bc -q -auth-plain -user "%emailFromAddress%" -pass "%emailPass%"
  127. }
  128.  
  129. checkTags:
  130. loop
  131. {
  132. site_ := site%a_index%
  133. site__short := site%a_index%_short
  134. if site_ =
  135. break
  136.  
  137. fileDelete, tmp_tag.html
  138. urlDownloadToFile, %site_%, tmp_tag.html
  139. fileRead, tag_fileContent, tmp_tag.html
  140. fileDelete, tmp_tag.html
  141. tag_fileContent = §§§K§J§KJ§§J§J§%tag_fileContent%§§L§L§L§OL§
  142. firstNewQuestion := regExReplace(tag_fileContent,"U)§§§K§J§KJ§§J§J§[wW]*<div class=[W]summary[W]>[W]*<h3><a href=[W]([^>]+)[W] class=[W]question-hyperlink[W]>[wW]*§§L§L§L§OL§","$1")
  143. tmp := lastNewQuestion_%site__short%
  144. if firstNewQuestion != %tmp%
  145. {
  146. tooltip, New Question for Tag "%site__short%"!!`n(%firstNewQuestion%)
  147. IniWrite, %firstNewQuestion%, config.ini, %site__short%, lastNewQuestion
  148. lastNewQuestion_%site__short% = %firstNewQuestion%
  149. if gmail_accountName !=
  150. {
  151. accn = %gmail_accountName%@gmail.com
  152. FormatTime, CurrentDateTime, M/d/yyyy, yyyy_MM_dd_H.mm
  153. msg = New Question for Tag "%site__short%"!!`n(%firstNewQuestion%)`n`nAlso see %site_%.`n`n(Sent from ahk-application Desktop @ %CurrentDateTime%)
  154. sendMail(accn,gmail_accountPass,acc,"New Stack Exchange notification",msg)
  155. }
  156. msgbox,4,, New Question for Tag "%site__short%"!!`n(%firstNewQuestion%)`n`nOpen "%site_%" in Browser now?
  157. ifmsgbox yes
  158. run %site_%
  159. sleep, 1500
  160. tooltip
  161. }
  162. }
  163.  
  164. return
  165.  
  166. checkInbox:
  167.  
  168. fileDelete, tmp_inbox.html
  169. urlDownloadToFile, *0 %linkToTheUserprofileInbox%, tmp_inbox.html
  170. fileRead, inbox_fileContent, tmp_inbox.html
  171. fileDelete, tmp_inbox.html
  172. ifinstring, inbox_fileContent, sign up
  173. {
  174. msgbox, Inbox check failed! You're not logged in!`nImportant: You need to be logged in permanenlty to StackExchange WITHIN INTERNET EXPLORER. Ahk accesses cache from there.
  175. return
  176. }
  177. inbox_fileContent = §§§K§J§KJ§§J§J§%inbox_fileContent%§§L§L§L§OL§
  178. firstNewInbox := regExReplace(inbox_fileContent, "U)§§§K§J§KJ§§J§J§[wW]*<table class=[W]history-table[W]>[Ww]*<span[Ww]*>([^n]+)</span>[Ww]*§§L§L§L§OL§", "$1")
  179. if firstNewInbox != %lastInbox%
  180. {
  181. tooltip, New Inbox Item!!`n(%firstNewInbox%)
  182. IniWrite, %firstNewInbox%, config.ini, Inbox, lastInbox
  183. lastInbox = %firstNewInbox%
  184. if gmail_accountName !=
  185. {
  186. accn = %gmail_accountName%@gmail.com
  187. FormatTime, CurrentDateTime, M/d/yyyy, yyyy_MM_dd_H.mm
  188. msg = New Inbox Item!!`n(%firstNewInbox%)`n`nAlso see %linkToTheUserprofileInbox%.`n`n(Sent from ahk-application Desktop @ %CurrentDateTime%)
  189. sendMail(accn,gmail_accountPass,acc,"New Stack Exchange notification",msg)
  190. }
  191. msgbox,4,, New Inbox Item!!`n(%firstNewInbox%)`n`nOpen "%linkToTheUserprofileInbox%" in Browser now?
  192. ifmsgbox yes
  193. run %linkToTheUserprofileInbox%
  194. sleep, 1500
  195. tooltip
  196. }
  197.  
  198. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement