Commit aedab946dc5d6038c92357933af5263d5789026e
- Diff rendering mode:
- inline
- side by side
src/w.mod
(57 / 1)
|   | |||
| 16 | 16 | IMPORT ProgExec; | |
| 17 | 17 | IMPORT StringParse, StreamFile, Strings; | |
| 18 | 18 | IMPORT Timers, TextIO; | |
| 19 | IMPORT util; | ||
| 19 | IMPORT util, p6Fifo; | ||
| 20 | 20 | ||
| 21 | 21 | PROCEDURE wakeupIB(parse : Message.Parse); | |
| 22 | 22 | (* have the bot wake ib up *) | |
| … | … | ||
| 43 | 43 | Message.PrintLine(parse.chan, "Sorry, I can't log in to ib right now."); | |
| 44 | 44 | END; | |
| 45 | 45 | END wakeupIB; | |
| 46 | |||
| 47 | PROCEDURE Weather(parse: Message.Parse); | ||
| 48 | (* uses Google to get the weather in some location *) | ||
| 49 | CONST | ||
| 50 | call = "lynx -dump -width=200 -nolist -accept_all_cookies 'http://www.google.com/search?q=weather+"; | ||
| 51 | (* Look for Humidity, grab it and the previous 4 lines, remove newlines, | ||
| 52 | remove 'Add to iGoogle', convert multiple spaces to a single space. *) | ||
| 53 | filter = "| grep -B5 Humidity | tr -d '\n' |sed 's/Add\ to\ iGoogle//' |sed 's/^ *//;s/ *$//;s/ \{1,\}/ /g' "; | ||
| 54 | |||
| 55 | VAR | ||
| 56 | command, null, target, result, str: Message.strType; | ||
| 57 | res, pos : CARDINAL; | ||
| 58 | done, found: BOOLEAN; | ||
| 59 | |||
| 60 | BEGIN | ||
| 61 | util.CmdUsed(parse); | ||
| 62 | command :=""; null := ""; target := ""; result := ""; str :=""; | ||
| 63 | (* Extract the target - at the moment, it will only accept the command in lowercase *) | ||
| 64 | StringParse.Split("her ", parse.cmd, null, target); | ||
| 65 | StringParse.Clip(target); | ||
| 66 | StringParse.Strip(target); | ||
| 67 | |||
| 68 | (* Is there actually a target? *) | ||
| 69 | IF (LENGTH(target) < 2) THEN | ||
| 70 | Message.PrintLine(parse.chan, "For what location?"); | ||
| 71 | RETURN | ||
| 72 | END; | ||
| 73 | |||
| 74 | (* save target, format changes follow *) | ||
| 75 | str := target; | ||
| 76 | REPEAT | ||
| 77 | StringParse.Replace(target, " ", "+"); | ||
| 78 | UNTIL (NOT StringParse.InString(" ", target)); | ||
| 79 | |||
| 80 | FormStr.print(command, "%s%s'%s", call, target, filter); | ||
| 81 | (* make the call *) | ||
| 82 | p6Fifo.writeFIFO(command); | ||
| 83 | p6Fifo.readFIFO(result); | ||
| 84 | |||
| 85 | target := str; (* get rid of the the formatting changes *) | ||
| 86 | (* Check string for Humidity, or Current, if it's there, then the return is valid *) | ||
| 87 | IF StringParse.InString("Humidity", result) THEN | ||
| 88 | (* Error in my code somewhere isn't clearing the previous line, so I'm | ||
| 89 | manually trimming everything after the %. Must be in the FIFO, but I can't see where. *) | ||
| 90 | Strings.FindNext("%", result, 0, found, pos); | ||
| 91 | IF found THEN Strings.Delete(result, pos+1, LENGTH(result)) END; | ||
| 92 | str := result; | ||
| 93 | ELSE | ||
| 94 | FormStr.print(str, "I'm sorry, I couldn't find any weather for %s", target); | ||
| 95 | END; | ||
| 96 | |||
| 97 | Message.PrintLine(parse.chan, str); | ||
| 98 | EXCEPT | ||
| 99 | Message.PrintLine(parse.chan, "For what location?"); | ||
| 100 | RETURN; | ||
| 101 | END Weather; | ||
| 46 | 102 | ||
| 47 | 103 | (* whatis (man -f) *) | |
| 48 | 104 | PROCEDURE whatis(parse : Message.Parse); |

