WshShell = WScript.CreateObject("WScript.Shell"); WordObj = WScript.CreateObject("Word.Application"); ABC = "\n.ABCDEFGHIJKLMNOPQRSTUVWXYZ"; SELF = WScript.ScriptFullName; ////////////////////////////////////////////////// ALERT("NUMLOCK ON = RUN SCRIPT\n\nNUMLOCK OFF = STOP SCRIPT"); PAGE_SAVED = 0; WEB_BROWSER = "C:\\BIN\\KM75\\k-meleon.exe"; WEB_BROWSER_NAME = "meleon"; ORIGINAL_URL1 = "https://www.quantumonline.com/SearchDD.cfm?tickersymbol=$$$&sopt=symbol"; ORIGINAL_URL2 = "https://bigcharts.marketwatch.com/quickchart/quickchart.asp?symb=$$$"; CURRENT_DIRECTORY = cut(SELF, "\\", 0x10010); NEWLIST_FILE = CURRENT_DIRECTORY + "\\NEWLIST.TXT"; INPUT_FILE = CURRENT_DIRECTORY + "\\SYMBOL_LIST.TXT"; OUTPUT_FILE = CURRENT_DIRECTORY + "\\MYCOLLECTION.TXT"; SKIP_LIST_FILE = CURRENT_DIRECTORY + "\\SKIP_LIST.TXT"; ALREADY_DONE = ""; SYMBOLS = ReadFile(NEWLIST_FILE).toUpperCase(); SYMBOLS = tr(SYMBOLS, ABC).split("\n"); ALERT("ABOUT TO DOWNLOAD " + SYMBOLS.length + " STOCK DATA."); //MORE_SYMBOLS = []; //ALREADY_DONE = ReadFile(SKIP_LIST_FILE).toUpperCase(); //ALREADY_DONE = tr(ALREADY_DONE, ABC).split("\n"); //ALREADY_DONE = "|" + ALREADY_DONE.join("|") + "|"; ////ALERT("READ " + ALREADY_DONE.length + " SYMBOLS"); // //SYMBOLS = ReadFile(INPUT_FILE).toUpperCase(); //SYMBOLS = tr(SYMBOLS, ABC).split("\n"); //ALERT("READ " + SYMBOLS.length + " SYMBOLS"); //for (i = 0; i < SYMBOLS.length; i++) //{ // if (ALREADY_DONE.indexOf("|" + SYMBOLS[i] + "|") >= 0) // SYMBOLS[i] = ""; //} //RemoveDuplicates(SYMBOLS); //CreateFile(CURRENT_DIRECTORY + "\\NEWLIST.TXT", SYMBOLS.join("\r\n")); // //QUIT(0); // //for (i = 0; i < 10; i++) // ALERT(PickNextSymbol()); // // HEADER = "ListSymbol\tSymbol\tCUSIP\tPrevCUSIP\tExch\tCIK\tPhone\tWebsite\tAddr\tIPO\tName\tDescription\r\n"; if (FileExists(OUTPUT_FILE) == 0) CreateFile(OUTPUT_FILE, HEADER); TOTAL_COUNT = 1; CURRENT_SYMBOL = PickNextSymbol(); BEFORE_COMPANY_NAME = '
'; AFTER_COMPANY_NAME = '
'; BEFORE_STOCK_SYMBOL = 'Ticker Symbol:'; AFTER_STOCK_SYMBOL = '  '; BEFORE_STOCK_CUSIP = 'CUSIP:'; AFTER_STOCK_CUSIP = '  '; BEFORE_PREV_CUSIP = 'Previous CUSIP:'; AFTER_PREV_CUSIP = '  '; BEFORE_EXCHANGE = 'Exchange:'; AFTER_EXCHANGE = ''; BEFORE_WEBSITE = 'target="HOMEPAGE">'; // copy the text after the 2nd instance! AFTER_WEBSITE = ''; BEFORE_ADDRESS = 'Address:   '; AFTER_ADDRESS = ''; BEFORE_CIK = 'http://www.sec.gov/cgi-bin/browse-edgar?company=&CIK='; AFTER_CIK = '&'; BEFORE_PHONE = 'Main Phone Number'; // Remove html tags from this section AFTER_PHONE = 'Fax Number'; BEFORE_DESCR = ''; AFTER_DESCR = '
'; BEFORE_PREV_NAME = 'Previous Name:'; AFTER_PREV_NAME = ''; BEFORE_PREV_SYMBOL = 'Previous Ticker Symbol:'; AFTER_PREV_SYMBOL = ''; BEFORE_IPO = 'IPO'; AFTER_IPO = ''; URL1 = ORIGINAL_URL1; URL2 = ORIGINAL_URL2; URL1 = URL1.split("$$$").join(CURRENT_SYMBOL); URL2 = URL2.split("$$$").join(CURRENT_SYMBOL); RUN(QUOTE(WEB_BROWSER) + " " + QUOTE(URL1)); WAIT(1); WINFOCUS(WEB_BROWSER_NAME); WAIT(10); // LOAD PAGE FOR ABOUT 10 SECONDS... PRESS("^{u}"); // OPEN SOURCE CODE WAIT(6); //PRESS("^{a}"); // CTRL+A SELECT ALL //PRESS("^{INSERT}"); // COPY //WAIT(0.5); //DATA = ReadClipboardText(); WAIT(0.5); PRESS("%{f}"); // OPEN FILE MENU WAIT(0.5); PRESS("x"); // EXIT //Process_and_Save( DATA ); for (;;) { CURRENT_SYMBOL = PickNextSymbol(); URL = ORIGINAL_URL1; URL = URL.split("$$$").join(CURRENT_SYMBOL); WINFOCUS(WEB_BROWSER_NAME); WAIT(2); PRESS("+{TAB}"); // SHIFT+TAB WAIT(0.1); PRESS("{TAB}"); // TAB WAIT(0.1); PRESS(URL); // ENTER NEW URL PRESS("{ENTER}"); // LOAD NEW ADDRESS WAIT(4); // WAIT FOR PAGE LOAD PRESS("^{u}"); // OPEN SOURCE CODE WAIT(5); PRESS("%{f}"); // OPEN FILE MENU WAIT(0.1); PRESS("x"); // EXIT RUN("K:\\DESKTOP\\TRADES\\DATA_DOWNLOAD3\\COPYOVER.BAT"); // WAIT(4.5); // PRESS("^{a}"); // CTRL+A SELECT ALL // PRESS("^{INSERT}"); // COPY // DATA = ReadClipboardText(); // WAIT(0.2); // Process_and_Save( DATA ); } ALERT("PROCESSED " + TOTAL_COUNT + " STOCKS.\n\nSCRIPT ENDED."); EXIT(0); ////////////////////////////////////////////////// function PickNextSymbol() { var i, S; for (i = 0; i < SYMBOLS.length; i++) { S = Trim(SYMBOLS[i]).toUpperCase(); if (S == "") continue; if (ALREADY_DONE.indexOf("|" + S + "|") < 0) break; } ALREADY_DONE += S + "|"; return S; } ////////////////////////////////////////////////// // This function extracts a section from string S that lies between string L and R. // Returns an empty string if either L or R is not found. function Between(S, L, R, SKIP) { if (typeof(SKIP) === "undefined") SKIP = 1; var p1 = 0; for (var i = 0; i < SKIP; i++) { p1 = S.indexOf(L, p1); if (p1 < 0) return ""; p1 += L.length; } var p2 = S.indexOf(R, p1); if (p2 <= p1) return ""; return Trim(S.substring(p1, p2)); } ///////////////////////////////// function Process_and_Save(DATA) { if (DATA.indexOf("Check that you input the correct symbol.
") >= 0) { NEW_LINE = CURRENT_SYMBOL + "\t-\t-\t-\t-\r\n"; AppendFile(OUTPUT_FILE, NEW_LINE); return; } var STOCK_SYMBOL = uc(Between(DATA, BEFORE_STOCK_SYMBOL, AFTER_STOCK_SYMBOL)); var STOCK_CUSIP = uc(Between(DATA, BEFORE_STOCK_CUSIP, AFTER_STOCK_CUSIP)); var PREV_CUSIP = uc(Between(DATA, BEFORE_PREV_CUSIP, AFTER_PREV_CUSIP)); var EXCHANGE = Between(DATA, BEFORE_EXCHANGE, AFTER_EXCHANGE); var CIK = Between(DATA, BEFORE_CIK, AFTER_CIK); var PHONE = Between(DATA, BEFORE_PHONE, AFTER_PHONE); var WEBSITE = Between(DATA, BEFORE_WEBSITE, AFTER_WEBSITE, 2); var ADDRESS = Between(DATA, BEFORE_ADDRESS, AFTER_ADDRESS); var COMPANY_NAME = Between(DATA, BEFORE_COMPANY_NAME, AFTER_COMPANY_NAME); var DESCRIPTION = Between(DATA, BEFORE_DESCR, AFTER_DESCR); var PREV_NAME = Between(DATA, BEFORE_PREV_NAME, AFTER_PREV_NAME); var PREV_SYMBOL = Between(DATA, BEFORE_PREV_SYMBOL, AFTER_PREV_SYMBOL); PREV_NAME = Trim(StripHTML(PREV_NAME)); PREV_SYMBOL = Trim(StripHTML(PREV_SYMBOL)); var IPO = Between(DATA, BEFORE_IPO, AFTER_IPO); WEBSITE = Trim(TrimChar(WEBSITE, "/")); PHONE = Trim(StripHTML(PHONE)); PHONE = PHONE.substr(0, 20); IPO = Trim(StripHTML(IPO)); COMPANY_NAME = COMPANY_NAME.replace(/\t/g, " "); COMPANY_NAME = COMPANY_NAME.replace(/ /g, " "); DESCRIPTION = DESCRIPTION.replace(/\r\n/g, " "); DESCRIPTION = DESCRIPTION.replace(/\n/g, " "); DESCRIPTION = DESCRIPTION.replace(/\t/g, " "); DESCRIPTION = DESCRIPTION.replace(/ /g, " "); DESCRIPTION = StripHTML(DESCRIPTION); var SAVE_LIST = [STOCK_SYMBOL + (PREV_SYMBOL.length ? " (" + PREV_SYMBOL + ")" : ""), STOCK_CUSIP, PREV_CUSIP, EXCHANGE, CIK, PHONE, WEBSITE, ADDRESS, IPO, COMPANY_NAME + (PREV_NAME.length ? " (" + PREV_NAME + ")" : ""), DESCRIPTION]; var NEW_LINE = CURRENT_SYMBOL + "\t" + SAVE_LIST.join("\t") + "\r\n"; AppendFile(OUTPUT_FILE, NEW_LINE); TOTAL_COUNT++; } ////////////////////////////////////////////////// // // F U N C T I O N L I B R A R Y // function Abort_Script_If_Numlock_Is_OFF() { if (GetNumlockState() == 0) EXIT(0); } function PlayMP3(FILENAME) { WshShell.Run(QUOTE("C:\\BIN\\COMMAND\\PLAYMP3.EXE") + " " + QUOTE(FILENAME)); } function WINFOCUS(W) { Abort_Script_If_Numlock_Is_OFF(); WshShell.AppActivate(W); } function WAIT(MS) { Abort_Script_If_Numlock_Is_OFF(); MS *= 500; WScript.Sleep(MS); Abort_Script_If_Numlock_Is_OFF(); } function RUN(CMD) { Abort_Script_If_Numlock_Is_OFF(); WshShell.Run(CMD, 9); } function SAY(TEXT) { Abort_Script_If_Numlock_Is_OFF(); var VOICE = WScript.CreateObject("SAPI.SpVoice"); VOICE.Volume = 100; VOICE.Speak(TEXT); } function EXIT(E) { WordObj.Quit(); if (typeof(E) === "undefined") E = 0; WScript.Quit(E); } function QUIT(E) { WordObj.Quit(); if (typeof(E) === "undefined") E = 0; WScript.Quit(E); } function PRESS(KEYCODE) { WAIT(0.1); WshShell.SendKeys(KEYCODE); Abort_Script_If_Numlock_Is_OFF(); } function ALERT(MSG) { WScript.Echo(MSG); } function QUOTE(S) { return '"' + S + '"'; } function DEBUG(S) { ALERT("DEBUG:|" + S + "|"); } ////////////////////////////////////////////////// // This function positions our window in the center of the screen. function CENTER(W, H) { self.resizeTo(W, H); self.moveTo(Math.round((screen.width - W) / 2), Math.round((screen.height - H) / 2)); } ////////////////////////////////////////////////// // Creates and overwrites a text file and with a string. // Return 0 on success or 1 if an error occurred. // Global variable $a will hold an error message or the // word "SUCCESS" if there were no errors. // Usage: INTEGER = CreateFile(FILENAME, STRING) // function CreateFile(FILENAME, STRING) { $a = ""; var inASCII = 0; var inUNICODE = 1; var Overwrite = 1; var Do_Not_Overwrite = 0; try { var FSO = new ActiveXObject("Scripting.FileSystemObject"); var F = FSO.CreateTextFile(FILENAME, Overwrite, inASCII); F.Write(STRING); F.Close(); $a = "SUCCESS"; return 0; } catch (e) { $a = e.message; } return 1; } // Deletes a file. Return 0 on success or an error message. function DeleteFile(FILENAME, DELETE_READONLY) { try { FSO.DeleteFile(FILENAME, DELETE_READONLY); return 0; } catch(e) { return e.message; } } ////////////////////////////////////////////////// function TYPE(TEXT) { Abort_Script_If_Numlock_Is_OFF(); var i, t; for (i = 0; i < TEXT.length; i++) { t = TEXT.charAt(i); WAIT(10); if (i > 5) { t = TEXT.slice(i); i = TEXT.length; } PRESS(t); } } ////////////////////////////////////////////////// /* Most ASCII characters can be represented by the character itself. E.g, the key sequence FRED can be represented by "FRED". Some special keys, such as the control keys, function keys etc are encoded in a string enclosed by {braces} See the table below Key/Character SendKey Description ~ {~} Send a tilde (~) ! {!} Send an exclamation point (!) ^ {^} Send a caret (^) + {+} Send a plus sign (+) Backspace {BACKSPACE} or {BKSP} or {BS} Send a Backspace keystroke Break {BREAK} Send a Break keystroke Caps Lock {CAPSLOCK} Press the Caps Lock Key (toggle on or off) Clear {CLEAR} Clear the field Delete {DELETE} or {DEL} Send a Delete keystroke Insert {INSERT} or {INS} Send an Insert keystroke Cursor control arrows {LEFT} / {RIGHT} / {UP} / {DOWN} Send a Left/Right/Up/Down Arrow End {END} Send an End keystroke Enter {ENTER} or ~ Send an Enter keystroke Escape {ESCAPE} Send an Esc keystroke F1 through F16 {F1} through {F16} Send a Function keystroke Help {HELP} Send a Help keystroke Home {HOME} Send a Home keystroke Numlock {NUMLOCK} Send a Num Lock keystroke Page Down Page Up {PGDN} {PGUP} Send a Page Down or Page Up keystroke Print Screen {PRTSC} Send a Print Screen keystroke Scroll lock {SCROLLLOCK} Press the Scroll lock Key (toggle on or off) TAB {TAB} Send a TAB keystroke To specify keys combined with any combination of SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following: For SHIFT prefix with + For CTRL prefix with ^ For ALT prefix with % Example ' Open notepad Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "notepad.exe", 9 ' Give Notepad time to load WScript.Sleep 500 ' Type in Hello World WshShell.SendKeys "Hello World!" WshShell.SendKeys "{ENTER}" ' Add the date WshShell.SendKeys "{F5}" */ ////////////////////////////////////////////////// // // Returns the entire contents of a text or binary file. // Usage: STRING = ReadFile(FILENAME) // function ReadFile(FILENAME) { var F, FSO, DATA = ""; try { FSO = new ActiveXObject("Scripting.FileSystemObject"); F = FSO.OpenTextFile(FILENAME, 1); DATA = F.ReadAll(); F.Close(); return DATA; } catch (e) {} return ""; } ////////////////////////////////////////////////// // This function splits string into two parts // along the first occurrence of substring. // Returns the first part if CMD is 0x10. // Returns the second part if CMD is 1. // If substring is not found, returns the original // string if CMD is 0x100. Ignores case when // CMD is 0x1000. Starts searching from end of // string when CMD is 0x10000. // function cut(STR, SUB, CMD) { if (typeof(CMD) === "undefined") CMD = 0x111; STR += ""; SUB += ""; var P; if (CMD & 0x1000) P = (CMD & 0x10000) ? STR.toUpperCase().lastIndexOf(SUB) : STR.toUpperCase().indexOf(SUB); else P = (CMD & 0x10000) ? STR.lastIndexOf(SUB) : STR.indexOf(SUB); $a = $b = ""; if (P < 0) return (CMD & 256) ? STR : ""; $a = STR.substr(0, P); $b = STR.slice(P + SUB.length); return (CMD & 16 ? $a : '') + (CMD & 1 ? $b : ''); } ////////////////////////////////////////////////// // v2021.3.15 // This function removes all characters from STR // that do not appear anywhere in CHARSET, forcing // string to be only made up of the given characters. // Example: tr("cabbage cake", " abc") --> "cabba ca" // [This function has not been optimized yet.] // Usage: STRING = tr(STRING, STRING) // function tr(STR, CHARSET) { STR += ""; STR = STR.split(""); for (var i = 0; i < STR.length; i++) if (CHARSET.indexOf(STR[i]) < 0) STR[i] = ""; return STR.join(""); } ////////////////////////////////////////////////// // v2021.3.15 // This function returns 1 when Numlock is ON. // Returns 0 when Numlock is OFF. // Usage: INTEGER = GetNumlockState() // function GetNumlockState() { return (WordObj.NumLock) & 1; } ////////////////////////////////////////////////// // v2021.3.15 // This function returns 1 if the file exists. // Returns 0 if the file doesn't exist. // Usage: INTEGER = FileExists(FILENAME) // function FileExists(FILENAME) { var FSO, E = 0; try { FSO = new ActiveXObject("Scripting.FileSystemObject"); E = FSO.FileExists(FILENAME); } catch (e) {} return E; } ////////////////////////////////////////////////// // v2021.3.16 // This function copies all text from the clipboard. // This is done by creating an Internet Explorer // document in the background that contains a form // and a textbox for input. After pasting whatever // is on the clipboard into the textarea, we can // reads its contents and return the string. // This takes about 200ms. // // Usage: STRING = ReadClipboardText() // function ReadClipboardText() { var MSIE = WScript.CreateObject("InternetExplorer.Application"); MSIE.Visible = 0; MSIE.ToolBar = 0; MSIE.StatusBar = 0; MSIE.FullScreen = 1; MSIE.Navigate("about:blank"); /* MSIE.RegisterAsDropTarget = 0; WScript.Sleep(100); MSIE.Width = 600; MSIE.Height = 400; MSIE.Left = (MSIE.document.parentWindow.screen.availWidth - MSIE.Width) / 2; MSIE.Top = (MSIE.document.parentWindow.screen.availHeight - MSIE.Height) / 2; */ var HTML = "
"; WScript.Sleep(100); MSIE.Document.open(); MSIE.Document.write(HTML); MSIE.Document.close(); WScript.Sleep(100); PRESS("+{INSERT}"); WScript.Sleep(150); var COPIED = MSIE.Document.MAIN.INPUT.value + ""; WScript.Sleep(50); MSIE.Quit(); return COPIED; } ////////////////////////////////////////////////// function uc(S) { return S.toUpperCase(); } function lc(S) { return S.toLowerCase(); } ////////////////////////////////////////////////// // v2021.3.16 // This function adds a string to the end of a // file in ASCII mode. Return 0 on success or // returns 1 if something went wrong. The global // variable $a will hold a text string "SUCCESS" // if everything went well or an error message. // Usage: INTEGER = AppendFile(FILENAME, CONTENT) // function AppendFile(FILENAME, STRING) { $a = ""; var ForReading = 2; var ForWriting = 4; var ForAppending = 8; var inASCII_Format = 0; var inUNICODE_Format = -1; var Create_If_File_Doesnt_Exist = 1; var Do_Not_Create_If_File_Doesnt_Exist = 0; try { var FSO = new ActiveXObject("Scripting.FileSystemObject"); var F = FSO.OpenTextFile(FILENAME, ForAppending, Create_If_File_Doesnt_Exist, inASCII_Format); F.Write(STRING); F.Close(); return 0; } catch (e) { $a = e.message; } return 1; } ////////////////////////////////////////////////// // // This function removes whitespace before and after // text T and returns a new string. // Usage: STRING = Trim(STRING) // function Trim(T) { T += ""; var i, j, x; for (x = i = j = 0, i--; x < T.length; x++) if (T.charCodeAt(x) > 32) { if (i < 0) i = x; j = x + 1; } return T.slice(i, j); } ////////////////////////////////////////////////// // // This function is just like Trim() except it // removes characters specified in SUBSTR. // Usage: STRING = TrimChar(STRING, SUBSTR) // function TrimChar(STR, CHARLIST) { STR += ""; var L = STR.length, START = 0, LAST = 0; while (L--) { if (CHARLIST.indexOf(STR.substr(L, 1)) < 0) { START = L; if (LAST == 0) LAST = L + 1; } } return STR.substring(START, LAST); } ////////////////////////////////////////////////// // // This function strips html tags from a string // and returns the text portion only. // Usage: STRING = StripHTML(STRING) function StripHTML(S) { var i, c, SKIP = 0, OUTPUT = []; for (i = 0; i < S.length; i++) { c = S.charCodeAt(i); if (c == 60) SKIP = 1; if (SKIP == 0) OUTPUT.push(S.substr(i, 1)); if (c == 62) SKIP = 0; } OUTPUT = OUTPUT.join(""); OUTPUT = OUTPUT.replace(/\ /g, " "); OUTPUT = OUTPUT.replace(/\&/g, "&"); OUTPUT = OUTPUT.replace(/\t/g, " "); OUTPUT = OUTPUT.replace(/ /g, " "); return OUTPUT; } ////////////////////////////////////////////////// // This function sorts array A and removes duplicate elements. function RemoveDuplicates(A) { A.sort(); var LINE, i, j = 0, prev = ""; for (i = 0; i < A.length; i++) { LINE = Trim(A[i]); if (LINE == prev) LINE = ""; else prev = LINE; if (LINE.length) { if (j < i) A[j] = LINE; j++; } } A.length = j; } ////////////////////////////////////////////////// function uc(S) { return S.toUpperCase(); } function lc(S) { return S.toLowerCase(); } ////////////////////////////////////////////////// // v2019.12.9 // Returns one or more words from a string. // The string is treated as a list of words separated // by whitespace. In this case, a "whitespace" is any // character whose ASCII value is less than 33. This // includes new line characters, tab, space, null, etc. // PTR tells which word to grab starting with 1. // If PTR is 3, the third word is returned. // If PTR is not specified, the default value is 1. // COUNT tells how many words to return. Default is 1. // When COUNT has a negative value, returns every word // from PTR all the way to the end of the string. // The words in the return value will always be separated // by a space character regardless of how many spaces or // tabs were between them in the input string. // // Usage: STRING = GetWord(STRING, [PTR, [COUNT]]) // function GetWord(S, PTR, COUNT) { S += ""; if (typeof(PTR) === "undefined") PTR = 1; if (typeof(COUNT) === "undefined") COUNT = 1; if (S.length == 0 || COUNT == 0 || PTR >= S.length) return ""; if (PTR <= 0) PTR = 1; var i, START = -1, OUTPUT = []; for (i = 0; i <= S.length; i++) { if (S.charCodeAt(i) > 32) { if (START < 0) START = i; continue; } if (START >= 0) { if (PTR-- < 2) { OUTPUT.push(S.substring(START, i)); if (COUNT-- == 1) break; } START = -1; } } return OUTPUT.join(" "); } //////////////////////////////////////////////////