├── .gitignore ├── CHANGELOG.org ├── Eldev ├── LICENSE ├── Makefile ├── README.org ├── images ├── org-web-track-columns_01.png └── org-web-track-graph_01.png ├── makem.sh ├── manifest.scm ├── notes.org ├── org-web-track.el ├── org-web-track.info ├── org-web-track.texi └── tests ├── track-entry.org ├── unit-test--org-web-track.el ├── unit-test--report.el └── unit-test--update-entry.el /.gitignore: -------------------------------------------------------------------------------- 1 | /*-autoloads.el 2 | # Added automatically by ‘eldev init’. 3 | /.eldev 4 | /Eldev-local 5 | -------------------------------------------------------------------------------- /CHANGELOG.org: -------------------------------------------------------------------------------- 1 | #+title: Change log of Org Web Track 2 | #+language: en 3 | #+options: ':t toc:nil num:t 4 | #+startup: content 5 | 6 | * Version 0.1.1 on 2025-01-12 7 | :PROPERTIES: 8 | :CREATED: [2024-11-14 Thu 20:47] 9 | :END: 10 | 11 | - ~org-web-track-report~ can now display a visual graph 12 | If the command called with C-u prefix, a 2D boxes graph will appear, powered by org-plot capability. 13 | 14 | * Version 0.1.0 on 2024-10-17 15 | :PROPERTIES: 16 | :CREATED: [2024-09-20 Fri 18:20] 17 | :END: 18 | 19 | - BREAKING CHANGE: Filters in =org-web-track-selectors-alist= are no longer effective 20 | The filters, which were originally designed to serve as data processors for the values obtained by the selector, are now deprecated. Please consider integrating this process directly into the selector itself. Consequently, the format of each element in =org-web-track-selectors-alist= must be either a cons cell (URL-MATCH . SELECTOR) or a list (URL-MATCH SELECTORS...). 21 | - Dynamic websites have become supported 22 | With the newly introduced CONTENT-FETCHER mechanism, users can deal with dynamic sites such as JS-rendered pages as tracking targets. 23 | - Tracking entries can now hold their own HTTP headers 24 | Users are expected to call =org-web-track-set-http-headers= in order to define the HTTP headers to be sent for the tracking entry at point. Additionally, the variable =org-web-track-default-http-headers= has been added to define HTTP headers for all HTTP sessions. 25 | - The date format in the report have become configurable 26 | A new custom variable, =org-web-track-report-date-format=, has been introduced 27 | - =org-web-track-use-curl= can now be a string 28 | The existing variable, org-web-track-use-curl, can now be a string that specifies the path for the cURL executable. 29 | - =org-web-track-test-selector= has been removed 30 | Consider using =org-web-track-retrieve-values= which has almost the same argument list, instead. 31 | - Add a custom variable =org-web-track-trim-values= 32 | If non-nil, all values will be trimmed automatically. 33 | 34 | * Version 0.0.3 on 2024-07-19 35 | :PROPERTIES: 36 | :CREATED: [2024-07-11 Thu 14:43] 37 | :ID: e5022a8f-6c34-45c5-8135-a7abf2350867 38 | :END: 39 | 40 | - Change the default backend for fetching data from =url-retrieve= to cURL 41 | Users can still choose to use =url-retrieve= instead by setting 42 | =org-web-track-use-curl= to nil. 43 | - Add support for Unix Domain Socket server as an access target 44 | In addition to the WWW server, users can optionally access an HTTP server 45 | listening on a Unix Domain Socket by calling =org-web-track-setup-entry= with a 46 | C-u prefix to define a socket path. 47 | -------------------------------------------------------------------------------- /Eldev: -------------------------------------------------------------------------------- 1 | ; -*- mode: emacs-lisp; lexical-binding: t -*- 2 | 3 | ;; Autodetermined by `eldev init'. 4 | (eldev-use-package-archive 'melpa) 5 | 6 | (eldev-use-plugin 'autoloads) 7 | 8 | (eldev-add-extra-dependencies 'test 'mocker) 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # * makem.sh/Makefile --- Script to aid building and testing Emacs Lisp packages 2 | 3 | # URL: https://github.com/alphapapa/makem.sh 4 | # Version: 0.5 5 | 6 | # * Arguments 7 | 8 | # For consistency, we use only var=val options, not hyphen-prefixed options. 9 | 10 | # NOTE: I don't like duplicating the arguments here and in makem.sh, 11 | # but I haven't been able to find a way to pass arguments which 12 | # conflict with Make's own arguments through Make to the script. 13 | # Using -- doesn't seem to do it. 14 | 15 | ifdef install-deps 16 | INSTALL_DEPS = "--install-deps" 17 | endif 18 | ifdef install-linters 19 | INSTALL_LINTERS = "--install-linters" 20 | endif 21 | 22 | ifdef sandbox 23 | ifeq ($(sandbox), t) 24 | SANDBOX = --sandbox 25 | else 26 | SANDBOX = --sandbox=$(sandbox) 27 | endif 28 | endif 29 | 30 | ifdef debug 31 | DEBUG = "--debug" 32 | endif 33 | 34 | # ** Verbosity 35 | 36 | # Since the "-v" in "make -v" gets intercepted by Make itself, we have 37 | # to use a variable. 38 | 39 | verbose = $(v) 40 | 41 | ifneq (,$(findstring vvv,$(verbose))) 42 | VERBOSE = "-vvv" 43 | else ifneq (,$(findstring vv,$(verbose))) 44 | VERBOSE = "-vv" 45 | else ifneq (,$(findstring v,$(verbose))) 46 | VERBOSE = "-v" 47 | endif 48 | 49 | # * Rules 50 | 51 | # TODO: Handle cases in which "test" or "tests" are called and a 52 | # directory by that name exists, which can confuse Make. 53 | 54 | %: 55 | @./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) $(INSTALL_LINTERS) $(@) 56 | 57 | .DEFAULT: init 58 | init: 59 | @./makem.sh $(DEBUG) $(VERBOSE) $(SANDBOX) $(INSTALL_DEPS) $(INSTALL_LINTERS) 60 | 61 | test: 62 | guix shell -m manifest.scm -- eldev test 63 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | :PROPERTIES: 2 | :ID: 6467515a-587c-4c98-95fc-b2762f64608c 3 | :END: 4 | #+title: org-web-track.el - Web data tracking framework in Org Mode 5 | #+language: en 6 | #+options: ':t toc:nil num:t 7 | #+export_file_name: org-web-track.texi 8 | #+texinfo_filename: org-web-track.info 9 | #+texinfo_dir_category: Emacs 10 | #+texinfo_dir_title: Org Web Track: (org-web-track) 11 | #+texinfo_dir_desc: Web data tracking framework in Org Mode 12 | #+texinfo_header: @set MAINTAINERSITE @uref{https://github.com/p-snow/org-web-track,website} 13 | #+texinfo_header: @set MAINTAINER p-snow 14 | 15 | #+texinfo: @insertcopying 16 | 17 | #+html: MELPA 18 | #+html: MELPA Stable 19 | 20 | Org Web Track provides an Org Mode framework that assists users in managing their values of interest on a website or via a Web API. 21 | 22 | * Overview 23 | :PROPERTIES: 24 | :ID: e0c25a0f-2b49-44b6-909f-002db1b39887 25 | :END: 26 | 27 | Through the use of Org Web Track: 28 | - Any location in the web page or any piece in the web API response can be an item to track 29 | - Users can monitor changes for the item and manage them using the facilities of Org mode 30 | - A set of items to track can be reviewed with their updated values in an Org column view 31 | - Users can extract an Org table displaying value changes and create a visual graph using Gnuplot. 32 | 33 | #+html: 34 | #+html: 35 | 36 | ** Retrieving data 37 | :PROPERTIES: 38 | :ID: d38d3fb9-c29d-4c22-be74-2e0c31b80616 39 | :END: 40 | 41 | When users specify which snippet of data to track on web pages or web APIs, the following methods are available: 42 | 43 | - CSS selectors, which are applied against the source code of the web page 44 | - Elisp functions, which receive a DOM object or a JSON object from a web page or a web API and are expected to return a desired value from the argument 45 | - Shell commands, which take a page source or an API response as STDIN and are expected to print a desired value to STDOUT 46 | 47 | * Installation 48 | :PROPERTIES: 49 | :CREATED: [2023-06-16 Fri 09:56] 50 | :ID: 28618b56-b746-47f3-a13f-38d7e59ab766 51 | :END: 52 | 53 | #+cindex: Installation instructions 54 | 55 | Requirements: 56 | - Emacs 29.1 or higher 57 | - [[https://github.com/tkf/emacs-request][request.el]] v0.3.2 58 | - [[https://github.com/zweifisch/enlive][enlive]] v0.0.1 59 | 60 | ** MELPA package 61 | :PROPERTIES: 62 | :CREATED: [2025-01-12 Sun 17:04] 63 | :END: 64 | 65 | Org Web Track can be installed from MELPA using package.el as follows: 66 | 67 | 1. Add melpa to package-archives 68 | #+begin_src emacs-lisp 69 | (add-to-list 'package-archives 70 | '("melpa" . "https://melpa.org/packages/") 71 | t) 72 | #+end_src 73 | 2. Refresh package contents 74 | : M-x package-refresh-contents 75 | 3. Install Org Web Track 76 | : M-x package-install 77 | and select org-web-track 78 | 79 | * Basic Usage 80 | :PROPERTIES: 81 | :CREATED: [2023-06-16 Fri 09:56] 82 | :ID: 167f452d-19d4-4664-82a6-332e53eaf3b6 83 | :END: 84 | 85 | In this section, the basic Org Web Track mechanism and fundamental command usage are described. 86 | 87 | ** Defining Tracking Items 88 | :PROPERTIES: 89 | :ID: af45aae0-2011-4b22-b7dc-e156309964a7 90 | :END: 91 | 92 | #+vindex: org-web-track-selectors-alist 93 | Before setting up each tracking item, users need to define ~org-web-track-selectors-alist~, whose element consists of two components: URL-MATCH and SELECTOR. Each element is responsible for selecting a value for the specific URL that matches URL-MATCH, a regexp. The SELECTOR will then be applied to the content of the HTTP response at the URL to extract the resulting value. 94 | 95 | A single URL-MATCH is associated with one or more SELECTORS. Therefore, the element of the variable appears as either (URL-MATCH . SELECTOR) or (URL-MATCH SELECTORS...). Below is a typical example of how to set the variable: 96 | 97 | (setq org-web-track-selectors-alist '(("example\\.com/product" . [.final-price]))) 98 | 99 | This code define how to extract product prices at the site "example.com". In the site, the price posits in the tag whose class is "final-price". This case, SELECTOR is CSS selector, one of available formats. SELECTOR can be more than that. Please refer to the documentation of ~org-web-track-selectors-alist~ for more detail. 100 | 101 | This code dictates how to extract product prices from the site "example.com". On the site, the price is located within a tag whose class is "final-price". In this case, SELECTOR is a vector, which signifies a CSS selector. Besides this, SELECTOR can also be a function or a string. This means it can represent an Elisp procedure or a shell command respectively. For more details, please refer to the documentation of ~org-web-track-selectors-alist~. 102 | 103 | #+findex: org-web-track-setup-entry 104 | After appropriately defining ~org-web-track-selectors-alist~, users can set up each specific tracking item by calling ~org-web-track-setup-entry~ on the desired org entry or before the first heading to create a new one in the org buffer. Users will be prompted to input the tracking URL, and then the updated value will be retrieved, stored, and displayed in the echo area according to the aforementioned settings. 105 | 106 | #+begin_src org 107 | ,* Book ABC 108 | :PROPERTIES: 109 | :TRACK_URL: https://example.com/products/book-abc.html 110 | :TRACK_CURRENT_VALUE: $30 111 | :TRACK_LAST_UPDATED_TIME: [2024-07-18 Thu 16:57] 112 | :END: 113 | :LOGBOOK: 114 | - Update "$30" [2024-07-18 Thu 16:57] 115 | :END: 116 | #+end_src 117 | 118 | Some practical tracking item examples for specific real services are showcased on the Wiki page of the project website at [[https://github.com/p-snow/org-web-track/wiki]]. 119 | 120 | *** Sending Additional HTTP Headers 121 | :PROPERTIES: 122 | :ID: ac87e68c-81d2-48fc-ac66-effc6ef601da 123 | :END: 124 | 125 | #+vindex: org-web-track-default-http-headers 126 | #+findex: org-web-track-set-http-headers 127 | In an HTTP request message, a client can include a set of information known as an HTTP header, each element presented in a key-value pair format. This allows the client to send metadata to the server for various purposes, such as authentication or user identification. 128 | 129 | In Org Web Track, users can specify HTTP headers in a couple of ways. First, they can set a variable ~org-web-track-default-http-headers~ that is applied to every HTTP request. Second, they can execute a command ~org-web-track-set-http-headers~ that sets specific HTTP headers for individual entries. 130 | 131 | *** Dealing with Dinamic Website 132 | :PROPERTIES: 133 | :CREATED: [2024-10-08 Tue 19:07] 134 | :ID: 0e1cc98a-df9e-4989-8a86-669334869532 135 | :END: 136 | 137 | #+vindex: org-web-track-content-fetcher-alist 138 | The HTTP request backend of org-web-track, either cURL or url-retrieve, lacks the ability to read a dynamic website like a JS-rendered page. To work around this issue, org-web-track employs a delegation mechanism for fetching content. CONTENT-FETCHER in the org-web-track-content-fetcher-alist is used for this purpose. Users are free to implement any procedure using libraries such as Selenium or WebDriver in it. 139 | 140 | *** Accessing Unix Domain Socket Server 141 | :PROPERTIES: 142 | :ID: c9e75ee1-7b69-44a5-8deb-40279a1d8843 143 | :END: 144 | 145 | #+findex: org-web-track-set-unix-socket 146 | #+vindex: org-web-track-use-curl 147 | While org-web-track primarily focuses on the WWW server as the access target, users also have the option to connect to a Unix Domain Socket server, which provides HTTP services mainly on a local machine. A simple example of a Unix Socket server implementation complying with the org-web-track framework can be found at https://github.com/p-snow/socket-http-server. Using this feature, non-HTTP services, such as Unix shell commands, can be effectively utilized within the org-web-track framework. 148 | 149 | Users who want to access the Unix Domain Socket server must set the socket's path by calling ~org-web-track-set-unix-socket~ at the desired tracking item. When this feature is active, the value of the variable ~org-web-track-use-curl~ will not be respected. The cURL program will implicitly be used as the fetching backend since url-retrieve cannot access the Unix Socket Server. 150 | 151 | ** Updating Values 152 | :PROPERTIES: 153 | :CREATED: [2024-04-22 Mon 17:41] 154 | :ID: b21beb3b-9959-4125-bac3-5208ab9ffb4a 155 | :END: 156 | 157 | #+findex: org-web-track-update-entry 158 | #+findex: org-web-track-update-files 159 | #+vindex: org-web-track-files 160 | The simplest way to update the value is to call ~org-web-track-update-entry~ on the desired org entry. If the retrieved value is updated compared to the last value, the updated value will be stored as the TRACK_CURRENT_VALUE org property; otherwise, the entry will remain unchanged. 161 | 162 | Alternatively, bulk updating is supported. To enable bulk updating, users must first define ~org-web-track-files~. This variable should be a list of files in which all tracking items, identified by having the TRACK_URL property, are selected for bulk updating. To perform bulk updating, call ~org-web-track-update-files~. 163 | 164 | ** Displaying Column View 165 | :PROPERTIES: 166 | :ID: c0f5a319-d7b2-4792-8780-ca71cf934fd3 167 | :END: 168 | 169 | #+findex: org-web-track-columns 170 | Column view in org-mode is a feature that displays properties in a table, providing a clear and comprehensive perspective. org-web-track offers a specialized column view where updated values are juxtaposed with their previous values for tracking items. To display the column view, call ~org-web-track-columns~ in org buffer. 171 | 172 | #+findex: org-web-track-agenda-columns 173 | #+findex: org-web-track-agenda-update 174 | If tracking items are scattered across many files, ~org-web-track-agenda-columns~ is useful as all tracking items in the aforementioned ~org-web-track-files~ are gathered in the agenda column view. Users can also update any item in the agenda column view by calling ~org-web-track-agenda-update~. 175 | 176 | ** Reporting and Creating Graph 177 | :PROPERTIES: 178 | :ID: 589566da-80c5-491f-b1e2-8cbaef8ab387 179 | :END: 180 | 181 | All updated values from the past are logged in the entry using the existing org log note feature. Log notes have a fixed format and are placed in a drawer only if ~org-log-into-drawer~ is non-nil. 182 | 183 | #+findex: org-web-track-report 184 | ~org-web-track-report~ creates an Org table where all log note values in the current Org entry are listed in ascending order of time, showing the transition of values over time. If called with C-u prefix, the command creates a visual graph using Gnuplot. Note that creating a graph requires the Gnuplot Emacs package and Gnuplot itself. 185 | 186 | * Extended Examples 187 | :PROPERTIES: 188 | :ID: 68639330-230a-4ca2-b9e2-0e7f01022ea3 189 | :END: 190 | 191 | In this section, examples of how to utilize =org-web-track= extensively are showcased. 192 | 193 | ** Automatic Bulk Updating and Email Notifications 194 | 195 | While automatic updating may be ideal in certain situations, Org Web Track refrains from providing this feature directly to prevent potential data violations. However, users can enable automatic updating by calling ~org-web-track-update-entry~ or ~org-web-track-update-files~ from Elisp code. Below is an example implementation of automatic updates with email notifications scheduled for midnight. 196 | 197 | #+begin_src emacs-lisp 198 | (defun exp/email-updated () 199 | "Check for updates on all tracking items in `org-web-track-files' 200 | and email me the updated list of items formatted as requested." 201 | (let* ((message-kill-buffer-on-exit t) 202 | (mail-msg (mapconcat 203 | (lambda (chg) 204 | (org-with-point-at chg 205 | (let ((org-trust-scanner-tags t)) 206 | (format "%s\n\t%s\n" 207 | (substring-no-properties 208 | (org-get-heading t t t t)) 209 | (org-web-track-current-changes nil "%p => %c" " | "))))) 210 | (org-web-track-update-files)))) 211 | (unless (string-blank-p mail-msg) 212 | ;; SMTP settings are required in advance (see smtpmail-xxx vaiables) 213 | (message-mail user-mail-address "Web Tracking Notification") 214 | (message-goto-body) 215 | (insert mail-msg) 216 | (message-send-and-exit)))) 217 | 218 | (require 'midnight) 219 | (add-hook 'midnight-hook #'exp/email-updated) 220 | (midnight-mode 1) 221 | #+end_src 222 | 223 | * Q&A 224 | 225 | ** Network Certificate Issue 226 | 227 | Non-interactive invocation for ~org-web-track-update-entry~ may fail due to an unverified network certificate. This issue can occur when accessing a website that offers an unverified certificate, and the variable ~network-security-level~ is set to 'medium' or higher. To address the issue, accept the certificate by calling the ~org-web-track-update-entry~ command interactively up-front. 228 | 229 | * License 230 | 231 | GPLv3 232 | 233 | * Indices 234 | :PROPERTIES: 235 | :CUSTOM_ID: h:dd530040-de9d-4f2b-8dfd-d8b8f14c058e 236 | :END: 237 | 238 | ** Function index 239 | :PROPERTIES: 240 | :INDEX: fn 241 | :CUSTOM_ID: h:317b8c20-6dc1-4390-a20a-d01d75a48ccb 242 | :END: 243 | 244 | ** Variable index 245 | :PROPERTIES: 246 | :INDEX: vr 247 | :END: 248 | 249 | ** Concept index 250 | :PROPERTIES: 251 | :INDEX: cp 252 | :END: 253 | 254 | # Local Variables: 255 | # eval: (add-hook 'after-save-hook #' org-texinfo-export-to-info nil t) 256 | # End: 257 | -------------------------------------------------------------------------------- /images/org-web-track-columns_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p-snow/org-web-track/2cf9367ef6f8800fa058a8ca30cbb6f2e75fe4de/images/org-web-track-columns_01.png -------------------------------------------------------------------------------- /images/org-web-track-graph_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p-snow/org-web-track/2cf9367ef6f8800fa058a8ca30cbb6f2e75fe4de/images/org-web-track-graph_01.png -------------------------------------------------------------------------------- /makem.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # * makem.sh --- Script to aid building and testing Emacs Lisp packages 4 | 5 | # URL: https://github.com/alphapapa/makem.sh 6 | # Version: 0.7.1 7 | 8 | # * Commentary: 9 | 10 | # makem.sh is a script that helps to build, lint, and test Emacs Lisp 11 | # packages. It aims to make linting and testing as simple as possible 12 | # without requiring per-package configuration. 13 | 14 | # It works similarly to a Makefile in that "rules" are called to 15 | # perform actions such as byte-compiling, linting, testing, etc. 16 | 17 | # Source and test files are discovered automatically from the 18 | # project's Git repo, and package dependencies within them are parsed 19 | # automatically. 20 | 21 | # Output is simple: by default, there is no output unless errors 22 | # occur. With increasing verbosity levels, more detail gives positive 23 | # feedback. Output is colored by default to make reading easy. 24 | 25 | # The script can run Emacs with the developer's local Emacs 26 | # configuration, or with a clean, "sandbox" configuration that can be 27 | # optionally removed afterward. This is especially helpful when 28 | # upstream dependencies may have released new versions that differ 29 | # from those installed in the developer's personal configuration. 30 | 31 | # * License: 32 | 33 | # This program is free software; you can redistribute it and/or modify 34 | # it under the terms of the GNU General Public License as published by 35 | # the Free Software Foundation, either version 3 of the License, or 36 | # (at your option) any later version. 37 | 38 | # This program is distributed in the hope that it will be useful, 39 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 40 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 41 | # GNU General Public License for more details. 42 | 43 | # You should have received a copy of the GNU General Public License 44 | # along with this program. If not, see . 45 | 46 | # * Functions 47 | 48 | function usage { 49 | cat <$file <$file <$file <"$file" <$file <"$file" <$file <&1) 337 | 338 | # Set output file. 339 | output_file=$(mktemp) || die "Unable to make output file." 340 | paths_temp+=("$output_file") 341 | 342 | # Run Emacs. 343 | debug "run_emacs: ${emacs_command[@]} $@ &>\"$output_file\"" 344 | "${emacs_command[@]}" "$@" &>"$output_file" 345 | 346 | # Check exit code and output. 347 | exit=$? 348 | [[ $exit != 0 ]] \ 349 | && debug "Emacs exited non-zero: $exit" 350 | 351 | [[ $verbose -gt 1 || $exit != 0 ]] \ 352 | && cat $output_file 353 | 354 | return $exit 355 | } 356 | 357 | # ** Compilation 358 | 359 | function batch-byte-compile { 360 | debug "batch-byte-compile: ERROR-ON-WARN:$compile_error_on_warn" 361 | 362 | [[ $compile_error_on_warn ]] && local error_on_warn=(--eval "(setq byte-compile-error-on-warn t)") 363 | 364 | run_emacs \ 365 | --load "$(elisp-byte-compile-file)" \ 366 | "${error_on_warn[@]}" \ 367 | --eval "(unless (makem-batch-byte-compile) (kill-emacs 1))" \ 368 | "$@" 369 | } 370 | 371 | function byte-compile-file { 372 | debug "byte-compile: ERROR-ON-WARN:$compile_error_on_warn" 373 | local file="$1" 374 | 375 | [[ $compile_error_on_warn ]] && local error_on_warn=(--eval "(setq byte-compile-error-on-warn t)") 376 | 377 | # FIXME: Why is the line starting with "&& verbose 3" not indented properly? Emacs insists on indenting it back a level. 378 | run_emacs \ 379 | --load "$(elisp-byte-compile-file)" \ 380 | "${error_on_warn[@]}" \ 381 | --eval "(pcase-let ((\`(,num-errors ,num-warnings) (makem-byte-compile-file \"$file\"))) (when (or (and byte-compile-error-on-warn (not (zerop num-warnings))) (not (zerop num-errors))) (kill-emacs 1)))" \ 382 | && verbose 3 "Compiling $file finished without errors." \ 383 | || { verbose 3 "Compiling file failed: $file"; return 1; } 384 | } 385 | 386 | # ** Files 387 | 388 | function submodules { 389 | # Echo a list of submodules's paths relative to the repo root. 390 | # TODO: Parse with bash regexp instead of cut. 391 | git submodule status | awk '{print $2}' 392 | } 393 | 394 | function project-root { 395 | # Echo the root of the project (or superproject, if running from 396 | # within a submodule). 397 | root_dir=$(git rev-parse --show-superproject-working-tree) 398 | [[ $root_dir ]] || root_dir=$(git rev-parse --show-toplevel) 399 | [[ $root_dir ]] || error "Can't find repo root." 400 | 401 | echo "$root_dir" 402 | } 403 | 404 | function files-project { 405 | # Echo a list of files in project; or with $1, files in it 406 | # matching that pattern with "git ls-files". Excludes submodules. 407 | [[ $1 ]] && pattern="/$1" || pattern="." 408 | 409 | local excludes 410 | for submodule in $(submodules) 411 | do 412 | excludes+=(":!:$submodule") 413 | done 414 | 415 | git ls-files -- "$pattern" "${excludes[@]}" 416 | } 417 | 418 | function dirs-project { 419 | # Echo list of directories to be used in load path. 420 | files-project-feature | dirnames 421 | files-project-test | dirnames 422 | } 423 | 424 | function files-project-elisp { 425 | # Echo list of Elisp files in project. 426 | files-project 2>/dev/null \ 427 | | grep -E "\.el$" \ 428 | | filter-files-exclude-default \ 429 | | filter-files-exclude-args 430 | } 431 | 432 | function files-project-feature { 433 | # Echo list of Elisp files that are not tests and provide a feature. 434 | files-project-elisp \ 435 | | grep -E -v "$test_files_regexp" \ 436 | | filter-files-feature 437 | } 438 | 439 | function files-project-test { 440 | # Echo list of Elisp test files. 441 | files-project-elisp | grep -E "$test_files_regexp" 442 | } 443 | 444 | function dirnames { 445 | # Echo directory names for files on STDIN. 446 | while read file 447 | do 448 | dirname "$file" 449 | done 450 | } 451 | 452 | function filter-files-exclude-default { 453 | # Filter out paths (STDIN) which should be excluded by default. 454 | grep -E -v "(/\.cask/|-autoloads\.el|\.dir-locals)" 455 | } 456 | 457 | function filter-files-exclude-args { 458 | # Filter out paths (STDIN) which are excluded with --exclude. 459 | if [[ ${files_exclude[@]} ]] 460 | then 461 | ( 462 | # We use a subshell to set IFS temporarily so we can send 463 | # the list of files to grep -F. This is ugly but more 464 | # correct than replacing spaces with line breaks. Note 465 | # that, for some reason, using IFS="\n" or IFS='\n' doesn't 466 | # work, and a literal line break seems to be required. 467 | IFS=" 468 | " 469 | grep -Fv "${files_exclude[*]}" 470 | ) 471 | else 472 | cat 473 | fi 474 | } 475 | 476 | function filter-files-feature { 477 | # Read paths on STDIN and echo ones that (provide 'a-feature). 478 | while read path 479 | do 480 | grep -E "^\\(provide '" "$path" &>/dev/null \ 481 | && echo "$path" 482 | done 483 | } 484 | 485 | function args-load-files { 486 | # For file in $@, echo "--load $file". 487 | for file in "$@" 488 | do 489 | sans_extension=${file%%.el} 490 | printf -- '--load %q ' "$sans_extension" 491 | done 492 | } 493 | 494 | function args-load-path { 495 | # Echo load-path arguments. 496 | for path in $(dirs-project | sort -u) 497 | do 498 | printf -- '-L %q ' "$path" 499 | done 500 | } 501 | 502 | function test-files-p { 503 | # Return 0 if $files_project_test is non-empty. 504 | [[ "${files_project_test[@]}" ]] 505 | } 506 | 507 | function buttercup-tests-p { 508 | # Return 0 if Buttercup tests are found. 509 | test-files-p || die "No tests found." 510 | debug "Checking for Buttercup tests..." 511 | 512 | grep "(require 'buttercup)" "${files_project_test[@]}" &>/dev/null 513 | } 514 | 515 | function ert-tests-p { 516 | # Return 0 if ERT tests are found. 517 | test-files-p || die "No tests found." 518 | debug "Checking for ERT tests..." 519 | 520 | # We check for this rather than "(require 'ert)", because ERT may 521 | # already be loaded in Emacs and might not be loaded with 522 | # "require" in a test file. 523 | grep "(ert-deftest" "${files_project_test[@]}" &>/dev/null 524 | } 525 | 526 | function package-main-file { 527 | # Echo the package's main file. 528 | file_pkg=$(files-project "*-pkg.el" 2>/dev/null) 529 | 530 | if [[ $file_pkg ]] 531 | then 532 | # Use *-pkg.el file if it exists. 533 | echo "$file_pkg" 534 | else 535 | # Use shortest filename (a sloppy heuristic that will do for now). 536 | for file in "${files_project_feature[@]}" 537 | do 538 | echo ${#file} "$file" 539 | done \ 540 | | sort -h \ 541 | | head -n1 \ 542 | | sed -r 's/^[[:digit:]]+ //' 543 | fi 544 | } 545 | 546 | function dependencies { 547 | # Echo list of package dependencies. 548 | 549 | # Search package headers. Use -a so grep won't think that an Elisp file containing 550 | # control characters (rare, but sometimes necessary) is binary and refuse to search it. 551 | grep -E -a -i '^;; Package-Requires: ' $(files-project-feature) $(files-project-test) \ 552 | | grep -E -o '\([^([:space:]][^)]*\)' \ 553 | | grep -E -o '^[^[:space:])]+' \ 554 | | sed -r 's/\(//g' \ 555 | | grep -E -v '^emacs$' # Ignore Emacs version requirement. 556 | 557 | # Search Cask file. 558 | if [[ -r Cask ]] 559 | then 560 | grep -E '\(depends-on "[^"]+"' Cask \ 561 | | sed -r -e 's/\(depends-on "([^"]+)".*/\1/g' 562 | fi 563 | 564 | # Search -pkg.el file. 565 | if [[ $(files-project "*-pkg.el" 2>/dev/null) ]] 566 | then 567 | sed -nr 's/.*\(([-[:alnum:]]+)[[:blank:]]+"[.[:digit:]]+"\).*/\1/p' $(files-project- -- -pkg.el 2>/dev/null) 568 | fi 569 | } 570 | 571 | # ** Sandbox 572 | 573 | function sandbox { 574 | verbose 2 "Initializing sandbox..." 575 | 576 | # *** Sandbox arguments 577 | 578 | # MAYBE: Optionally use branch-specific sandbox? 579 | 580 | # Check or make user-emacs-directory. 581 | if [[ $sandbox_dir ]] 582 | then 583 | # Directory given as argument: ensure it exists. 584 | if ! [[ -d $sandbox_dir ]] 585 | then 586 | debug "Making sandbox directory: $sandbox_dir" 587 | mkdir -p "$sandbox_dir" || die "Unable to make sandbox dir." 588 | fi 589 | 590 | # Add Emacs version-specific subdirectory, creating if necessary. 591 | sandbox_dir="$sandbox_dir/$(emacs-version)" 592 | if ! [[ -d $sandbox_dir ]] 593 | then 594 | mkdir "$sandbox_dir" || die "Unable to make sandbox subdir: $sandbox_dir" 595 | fi 596 | else 597 | # Not given: make temp directory, and delete it on exit. 598 | local sandbox_dir=$(mktemp -d) || die "Unable to make sandbox dir." 599 | paths_temp+=("$sandbox_dir") 600 | fi 601 | 602 | # Make argument to load init file if it exists. 603 | init_file="$sandbox_dir/init.el" 604 | 605 | # Set sandbox args. This is a global variable used by the run_emacs function. 606 | args_sandbox=( 607 | --title "makem.sh: $(basename $(pwd)) (sandbox: $sandbox_dir)" 608 | --eval "(setq user-emacs-directory (file-truename \"$sandbox_dir\"))" 609 | --load package 610 | --eval "(setq package-user-dir (expand-file-name \"elpa\" user-emacs-directory))" 611 | --eval "(setq user-init-file (file-truename \"$init_file\"))" 612 | ) 613 | 614 | # Add package-install arguments for dependencies. 615 | if [[ $install_deps ]] 616 | then 617 | local deps=($(dependencies)) 618 | debug "Installing dependencies: ${deps[@]}" 619 | 620 | # Ensure built-in packages get upgraded to newer versions from ELPA. 621 | args_sandbox_package_install+=(--eval "(setq package-install-upgrade-built-in t)") 622 | 623 | for package in "${deps[@]}" 624 | do 625 | args_sandbox_package_install+=(--eval "(package-install '$package)") 626 | done 627 | fi 628 | 629 | # Add package-install arguments for linters. 630 | if [[ $install_linters ]] 631 | then 632 | debug "Installing linters: package-lint relint" 633 | 634 | args_sandbox_package_install+=( 635 | --eval "(package-install 'elsa)" 636 | --eval "(package-install 'package-lint)" 637 | --eval "(package-install 'relint)") 638 | fi 639 | 640 | # *** Install packages into sandbox 641 | 642 | if [[ ${args_sandbox_package_install[@]} ]] 643 | then 644 | # Initialize the sandbox (installs packages once rather than for every rule). 645 | verbose 1 "Installing packages into sandbox..." 646 | 647 | run_emacs \ 648 | --eval "(package-refresh-contents)" \ 649 | "${args_sandbox_package_install[@]}" \ 650 | && success "Packages installed." \ 651 | || die "Unable to initialize sandbox." 652 | fi 653 | 654 | verbose 2 "Sandbox initialized." 655 | } 656 | 657 | # ** Utility 658 | 659 | function cleanup { 660 | # Remove temporary paths (${paths_temp[@]}). 661 | 662 | for path in "${paths_temp[@]}" 663 | do 664 | if [[ $debug ]] 665 | then 666 | debug "Debugging enabled: not deleting temporary path: $path" 667 | elif [[ -r $path ]] 668 | then 669 | rm -rf "$path" 670 | else 671 | debug "Temporary path doesn't exist, not deleting: $path" 672 | fi 673 | done 674 | } 675 | 676 | function echo-unset-p { 677 | # Echo 0 if $1 is set, otherwise 1. IOW, this returns the exit 678 | # code of [[ $1 ]] as STDOUT. 679 | [[ $1 ]] 680 | echo $? 681 | } 682 | 683 | function ensure-package-available { 684 | # If package $1 is available, return 0. Otherwise, return 1, and 685 | # if $2 is set, give error otherwise verbose. Outputting messages 686 | # here avoids repetition in callers. 687 | local package=$1 688 | local direct_p=$2 689 | 690 | if ! run_emacs --load $package &>/dev/null 691 | then 692 | if [[ $direct_p ]] 693 | then 694 | error "$package not available." 695 | else 696 | verbose 2 "$package not available." 697 | fi 698 | return 1 699 | fi 700 | } 701 | 702 | function ensure-tests-available { 703 | # If tests of type $1 (like "ERT") are available, return 0. Otherwise, if 704 | # $2 is set, give an error and return 1; otherwise give verbose message. $1 705 | # should have a corresponding predicate command, like ert-tests-p for ERT. 706 | local test_name=$1 707 | local test_command="${test_name,,}-tests-p" # Converts name to lowercase. 708 | local direct_p=$2 709 | 710 | if ! $test_command 711 | then 712 | if [[ $direct_p ]] 713 | then 714 | error "$test_name tests not found." 715 | else 716 | verbose 2 "$test_name tests not found." 717 | fi 718 | return 1 719 | fi 720 | } 721 | 722 | function echo_color { 723 | # This allows bold, italic, etc. without needing a function for 724 | # each variation. 725 | local color_code="COLOR_$1" 726 | shift 727 | 728 | if [[ $color ]] 729 | then 730 | echo -e "${!color_code}${@}${COLOR_off}" 731 | else 732 | echo "$@" 733 | fi 734 | } 735 | function debug { 736 | if [[ $debug ]] 737 | then 738 | function debug { 739 | echo_color yellow "DEBUG ($(ts)): $@" >&2 740 | } 741 | debug "$@" 742 | else 743 | function debug { 744 | true 745 | } 746 | fi 747 | } 748 | function error { 749 | echo_color red "ERROR ($(ts)): $@" >&2 750 | ((errors++)) 751 | return 1 752 | } 753 | function die { 754 | [[ $@ ]] && error "$@" 755 | exit $errors 756 | } 757 | function log { 758 | echo "LOG ($(ts)): $@" >&2 759 | } 760 | function log_color { 761 | local color_name=$1 762 | shift 763 | echo_color $color_name "LOG ($(ts)): $@" >&2 764 | } 765 | function success { 766 | if [[ $verbose -ge 2 ]] 767 | then 768 | log_color green "$@" >&2 769 | fi 770 | } 771 | function verbose { 772 | # $1 is the verbosity level, rest are echoed when appropriate. 773 | if [[ $verbose -ge $1 ]] 774 | then 775 | [[ $1 -eq 1 ]] && local color_name=blue 776 | [[ $1 -eq 2 ]] && local color_name=cyan 777 | [[ $1 -ge 3 ]] && local color_name=white 778 | 779 | shift 780 | log_color $color_name "$@" >&2 781 | fi 782 | } 783 | 784 | function ts { 785 | date "+%Y-%m-%d %H:%M:%S" 786 | } 787 | 788 | function emacs-version { 789 | # Echo Emacs version number. 790 | 791 | # Don't use run_emacs function, which does more than we need. 792 | "${emacs_command[@]}" -Q --batch --eval "(princ emacs-version)" \ 793 | || die "Unable to get Emacs version." 794 | } 795 | 796 | function rule-p { 797 | # Return 0 if $1 is a rule. 798 | [[ $1 =~ ^(lint-?|tests?)$ ]] \ 799 | || [[ $1 =~ ^(batch|interactive)$ ]] \ 800 | || [[ $(type -t "$2" 2>/dev/null) =~ function ]] 801 | } 802 | 803 | # * Rules 804 | 805 | # These functions are intended to be called as rules, like a Makefile. 806 | # Some rules test $1 to determine whether the rule is being called 807 | # directly or from a meta-rule; if directly, an error is given if the 808 | # rule can't be run, otherwise it's skipped. 809 | 810 | function all { 811 | verbose 1 "Running all rules..." 812 | 813 | lint 814 | tests 815 | } 816 | 817 | function compile-batch { 818 | [[ $compile ]] || return 0 819 | unset compile # Only compile once. 820 | 821 | verbose 1 "Compiling..." 822 | verbose 2 "Batch-compiling files..." 823 | debug "Byte-compile files: ${files_project_byte_compile[@]}" 824 | 825 | batch-byte-compile "${files_project_byte_compile[@]}" 826 | } 827 | 828 | function compile-each { 829 | [[ $compile ]] || return 0 830 | unset compile # Only compile once. 831 | 832 | verbose 1 "Compiling..." 833 | debug "Byte-compile files: ${files_project_byte_compile[@]}" 834 | 835 | local compile_errors 836 | for file in "${files_project_byte_compile[@]}" 837 | do 838 | verbose 2 "Compiling file: $file..." 839 | byte-compile-file "$file" \ 840 | || compile_errors=t 841 | done 842 | 843 | [[ ! $compile_errors ]] 844 | } 845 | 846 | function compile { 847 | if [[ $compile = batch ]] 848 | then 849 | compile-batch "$@" 850 | else 851 | compile-each "$@" 852 | fi 853 | local status=$? 854 | 855 | if [[ $compile_error_on_warn ]] 856 | then 857 | # Linting: just return status code, because lint rule will print messages. 858 | [[ $status = 0 ]] 859 | else 860 | # Not linting: print messages here. 861 | [[ $status = 0 ]] \ 862 | && success "Compiling finished without errors." \ 863 | || error "Compiling failed." 864 | fi 865 | } 866 | 867 | function batch { 868 | # Run Emacs in batch mode with ${args_batch_interactive[@]} and 869 | # with project source and test files loaded. 870 | verbose 1 "Executing Emacs with arguments: ${args_batch_interactive[@]}" 871 | 872 | run_emacs \ 873 | $(args-load-files "${files_project_feature[@]}" "${files_project_test[@]}") \ 874 | "${args_batch_interactive[@]}" 875 | } 876 | 877 | function interactive { 878 | # Run Emacs interactively. Most useful with --sandbox and --install-deps. 879 | local load_file_args=$(args-load-files "${files_project_feature[@]}" "${files_project_test[@]}") 880 | verbose 1 "Running Emacs interactively..." 881 | verbose 2 "Loading files: ${load_file_args//--load /}" 882 | 883 | [[ $compile ]] && compile 884 | 885 | unset arg_batch 886 | run_emacs \ 887 | $load_file_args \ 888 | --eval "(load user-init-file)" \ 889 | "${args_batch_interactive[@]}" 890 | arg_batch="--batch" 891 | } 892 | 893 | function lint { 894 | verbose 1 "Linting..." 895 | 896 | lint-checkdoc 897 | lint-compile 898 | lint-declare 899 | # NOTE: Elint doesn't seem very useful at the moment. See comment 900 | # in lint-elint function. 901 | # lint-elint 902 | lint-indent 903 | lint-package 904 | lint-regexps 905 | } 906 | 907 | function lint-checkdoc { 908 | verbose 1 "Linting checkdoc..." 909 | 910 | local checkdoc_file="$(elisp-checkdoc-file)" 911 | paths_temp+=("$checkdoc_file") 912 | 913 | run_emacs \ 914 | --load="$checkdoc_file" \ 915 | "${files_project_feature[@]}" \ 916 | && success "Linting checkdoc finished without errors." \ 917 | || error "Linting checkdoc failed." 918 | } 919 | 920 | function lint-compile { 921 | verbose 1 "Linting compilation..." 922 | 923 | compile_error_on_warn=true 924 | compile "${files_project_byte_compile[@]}" \ 925 | && success "Linting compilation finished without errors." \ 926 | || error "Linting compilation failed." 927 | unset compile_error_on_warn 928 | } 929 | 930 | function lint-declare { 931 | verbose 1 "Linting declarations..." 932 | 933 | local check_declare_file="$(elisp-check-declare-file)" 934 | paths_temp+=("$check_declare_file") 935 | 936 | run_emacs \ 937 | --load "$check_declare_file" \ 938 | -f makem-check-declare-files-and-exit \ 939 | "${files_project_feature[@]}" \ 940 | && success "Linting declarations finished without errors." \ 941 | || error "Linting declarations failed." 942 | } 943 | 944 | function lint-elsa { 945 | verbose 1 "Linting with Elsa..." 946 | 947 | # MAYBE: Install Elsa here rather than in sandbox init, to avoid installing 948 | # it when not needed. However, we should be careful to be clear about when 949 | # packages are installed, because installing them does execute code. 950 | run_emacs \ 951 | --load elsa \ 952 | -f elsa-run-files-and-exit \ 953 | "${files_project_feature[@]}" \ 954 | && success "Linting with Elsa finished without errors." \ 955 | || error "Linting with Elsa failed." 956 | } 957 | 958 | function lint-elint { 959 | # NOTE: Elint gives a lot of spurious warnings, apparently because it doesn't load files 960 | # that are `require'd, so its output isn't very useful. But in case it's improved in 961 | # the future, and since this wrapper code already works, we might as well leave it in. 962 | verbose 1 "Linting with Elint..." 963 | 964 | local errors=0 965 | for file in "${files_project_feature[@]}" 966 | do 967 | verbose 2 "Linting with Elint: $file..." 968 | run_emacs \ 969 | --load "$(elisp-elint-file)" \ 970 | --eval "(makem-elint-file \"$file\")" \ 971 | && verbose 3 "Linting with Elint found no errors." \ 972 | || { error "Linting with Elint failed: $file"; ((errors++)) ; } 973 | done 974 | 975 | [[ $errors = 0 ]] \ 976 | && success "Linting with Elint finished without errors." \ 977 | || error "Linting with Elint failed." 978 | } 979 | 980 | function lint-indent { 981 | verbose 1 "Linting indentation..." 982 | 983 | # We load project source files as well, because they may contain 984 | # macros with (declare (indent)) rules which must be loaded to set 985 | # indentation. 986 | 987 | run_emacs \ 988 | --load "$(elisp-lint-indent-file)" \ 989 | $(args-load-files "${files_project_feature[@]}" "${files_project_test[@]}") \ 990 | --funcall makem-lint-indent-batch-and-exit \ 991 | "${files_project_feature[@]}" "${files_project_test[@]}" \ 992 | && success "Linting indentation finished without errors." \ 993 | || error "Linting indentation failed." 994 | } 995 | 996 | function lint-package { 997 | ensure-package-available package-lint $1 || return $(echo-unset-p $1) 998 | 999 | verbose 1 "Linting package..." 1000 | 1001 | run_emacs \ 1002 | --load package-lint \ 1003 | --eval "(setq package-lint-main-file \"$(package-main-file)\")" \ 1004 | --funcall package-lint-batch-and-exit \ 1005 | "${files_project_feature[@]}" \ 1006 | && success "Linting package finished without errors." \ 1007 | || error "Linting package failed." 1008 | } 1009 | 1010 | function lint-regexps { 1011 | ensure-package-available relint $1 || return $(echo-unset-p $1) 1012 | 1013 | verbose 1 "Linting regexps..." 1014 | 1015 | run_emacs \ 1016 | --load relint \ 1017 | --funcall relint-batch \ 1018 | "${files_project_source[@]}" \ 1019 | && success "Linting regexps finished without errors." \ 1020 | || error "Linting regexps failed." 1021 | } 1022 | 1023 | function tests { 1024 | verbose 1 "Running all tests..." 1025 | 1026 | test-ert 1027 | test-buttercup 1028 | } 1029 | 1030 | function test-ert-interactive { 1031 | verbose 1 "Running ERT tests interactively..." 1032 | 1033 | unset arg_batch 1034 | run_emacs \ 1035 | $(args-load-files "${files_project_test[@]}") \ 1036 | --eval "(ert-run-tests-interactively t)" 1037 | arg_batch="--batch" 1038 | } 1039 | 1040 | function test-buttercup { 1041 | ensure-tests-available Buttercup $1 || return $(echo-unset-p $1) 1042 | compile || die 1043 | 1044 | verbose 1 "Running Buttercup tests..." 1045 | 1046 | local buttercup_file="$(elisp-buttercup-file)" 1047 | paths_temp+=("$buttercup_file") 1048 | 1049 | run_emacs \ 1050 | $(args-load-files "${files_project_test[@]}") \ 1051 | --load "$buttercup_file" \ 1052 | --eval "(progn (setq backtrace-on-error-noninteractive nil) (buttercup-run))" \ 1053 | && success "Buttercup tests finished without errors." \ 1054 | || error "Buttercup tests failed." 1055 | } 1056 | 1057 | function test-ert { 1058 | ensure-tests-available ERT $1 || return $(echo-unset-p $1) 1059 | compile || die 1060 | 1061 | verbose 1 "Running ERT tests..." 1062 | debug "Test files: ${files_project_test[@]}" 1063 | 1064 | run_emacs \ 1065 | $(args-load-files "${files_project_test[@]}") \ 1066 | -f ert-run-tests-batch-and-exit \ 1067 | && success "ERT tests finished without errors." \ 1068 | || error "ERT tests failed." 1069 | } 1070 | 1071 | # * Defaults 1072 | 1073 | test_files_regexp='^((tests?|t)/)|-tests?.el$|^test-' 1074 | 1075 | emacs_command=("emacs") 1076 | errors=0 1077 | verbose=0 1078 | compile=true 1079 | arg_batch="--batch" 1080 | compile=each 1081 | 1082 | # MAYBE: Disable color if not outputting to a terminal. (OTOH, the 1083 | # colorized output is helpful in CI logs, and I don't know if, 1084 | # e.g. GitHub Actions logging pretends to be a terminal.) 1085 | color=true 1086 | 1087 | # TODO: Using the current directory (i.e. a package's repo root directory) in 1088 | # load-path can cause weird errors in case of--you guessed it--stale .ELC files, 1089 | # the zombie problem that just won't die. It's incredible how many different ways 1090 | # this problem presents itself. In this latest example, an old .ELC file, for a 1091 | # .EL file that had since been renamed, was present on my local system, which meant 1092 | # that an example .EL file that hadn't been updated was able to "require" that .ELC 1093 | # file's feature without error. But on another system (in this case, trying to 1094 | # setup CI using GitHub Actions), the old .ELC was not present, so the example .EL 1095 | # file was not able to load the feature, which caused a byte-compilation error. 1096 | 1097 | # In this case, I will prevent such example files from being compiled. But in 1098 | # general, this can cause weird problems that are tedious to debug. I guess 1099 | # the best way to fix it would be to actually install the repo's code as a 1100 | # package into the sandbox, but doing that would require additional tooling, 1101 | # pulling in something like Quelpa or package-build--and if the default recipe 1102 | # weren't being used, the actual recipe would have to be fetched off MELPA or 1103 | # something, which seems like getting too smart for our own good. 1104 | 1105 | # TODO: Emit a warning if .ELC files that don't match any .EL files are detected. 1106 | 1107 | # ** Colors 1108 | 1109 | COLOR_off='\e[0m' 1110 | COLOR_black='\e[0;30m' 1111 | COLOR_red='\e[0;31m' 1112 | COLOR_green='\e[0;32m' 1113 | COLOR_yellow='\e[0;33m' 1114 | COLOR_blue='\e[0;34m' 1115 | COLOR_purple='\e[0;35m' 1116 | COLOR_cyan='\e[0;36m' 1117 | COLOR_white='\e[0;37m' 1118 | 1119 | # ** Package system args 1120 | 1121 | args_package_archives=( 1122 | --eval "(add-to-list 'package-archives '(\"gnu\" . \"https://elpa.gnu.org/packages/\") t)" 1123 | --eval "(add-to-list 'package-archives '(\"melpa\" . \"https://melpa.org/packages/\") t)" 1124 | ) 1125 | 1126 | args_package_init=( 1127 | --eval "(package-initialize)" 1128 | ) 1129 | 1130 | # * Args 1131 | 1132 | args=$(getopt -n "$0" \ 1133 | -o dhce:E:i:s::vf:C \ 1134 | -l compile-batch,exclude:,emacs:,install-deps,install-linters,debug,debug-load-path,help,install:,verbose,file:,no-color,no-compile,sandbox:: \ 1135 | -- "$@") \ 1136 | || { usage; exit 1; } 1137 | eval set -- "$args" 1138 | 1139 | while true 1140 | do 1141 | case "$1" in 1142 | --install-deps) 1143 | install_deps=true 1144 | ;; 1145 | --install-linters) 1146 | install_linters=true 1147 | ;; 1148 | -d|--debug) 1149 | debug=true 1150 | verbose=2 1151 | args_debug=(--eval "(setq init-file-debug t)" 1152 | --eval "(setq debug-on-error t)") 1153 | ;; 1154 | --debug-load-path) 1155 | debug_load_path=true 1156 | ;; 1157 | -h|--help) 1158 | usage 1159 | exit 1160 | ;; 1161 | -c|--compile-batch) 1162 | debug "Compiling files in batch mode" 1163 | compile=batch 1164 | ;; 1165 | -E|--emacs) 1166 | shift 1167 | emacs_command=($1) 1168 | ;; 1169 | -i|--install) 1170 | shift 1171 | args_sandbox_package_install+=(--eval "(package-install '$1)") 1172 | ;; 1173 | -s|--sandbox) 1174 | sandbox=true 1175 | shift 1176 | sandbox_dir="$1" 1177 | 1178 | if ! [[ $sandbox_dir ]] 1179 | then 1180 | debug "No sandbox dir: installing dependencies." 1181 | install_deps=true 1182 | else 1183 | debug "Sandbox dir: $1" 1184 | fi 1185 | ;; 1186 | -v|--verbose) 1187 | ((verbose++)) 1188 | ;; 1189 | -e|--exclude) 1190 | shift 1191 | debug "Excluding file: $1" 1192 | files_exclude+=("$1") 1193 | ;; 1194 | -f|--file) 1195 | shift 1196 | args_files+=("$1") 1197 | ;; 1198 | --no-color) 1199 | unset color 1200 | ;; 1201 | -C|--no-compile) 1202 | unset compile 1203 | ;; 1204 | --) 1205 | # Remaining args (required; do not remove) 1206 | shift 1207 | rest=("$@") 1208 | break 1209 | ;; 1210 | esac 1211 | 1212 | shift 1213 | done 1214 | 1215 | debug "ARGS: $args" 1216 | debug "Remaining args: ${rest[@]}" 1217 | 1218 | # Set package elisp (which depends on --no-org-repo arg). 1219 | package_initialize_file="$(elisp-package-initialize-file)" 1220 | paths_temp+=("$package_initialize_file") 1221 | 1222 | # * Main 1223 | 1224 | trap cleanup EXIT INT TERM 1225 | 1226 | # Change to project root directory first. 1227 | cd "$(project-root)" 1228 | 1229 | # Discover project files. 1230 | files_project_feature=($(files-project-feature)) 1231 | files_project_test=($(files-project-test)) 1232 | files_project_byte_compile=("${files_project_feature[@]}" "${files_project_test[@]}") 1233 | 1234 | if [[ ${args_files[@]} ]] 1235 | then 1236 | # Add specified files. 1237 | files_project_feature+=("${args_files[@]}") 1238 | files_project_byte_compile+=("${args_files[@]}") 1239 | fi 1240 | 1241 | debug "EXCLUDING FILES: ${files_exclude[@]}" 1242 | debug "FEATURE FILES: ${files_project_feature[@]}" 1243 | debug "TEST FILES: ${files_project_test[@]}" 1244 | debug "BYTE-COMPILE FILES: ${files_project_byte_compile[@]}" 1245 | debug "PACKAGE-MAIN-FILE: $(package-main-file)" 1246 | 1247 | if ! [[ ${files_project_feature[@]} ]] 1248 | then 1249 | error "No files specified and not in a git repo." 1250 | exit 1 1251 | fi 1252 | 1253 | # Set load path. 1254 | args_load_paths=($(args-load-path)) 1255 | debug "LOAD PATH ARGS: ${args_load_paths[@]}" 1256 | 1257 | # If rules include linters and sandbox-dir is unspecified, install 1258 | # linters automatically. 1259 | if [[ $sandbox && ! $sandbox_dir ]] && [[ "${rest[@]}" =~ lint ]] 1260 | then 1261 | debug "Installing linters automatically." 1262 | install_linters=true 1263 | fi 1264 | 1265 | # Initialize sandbox. 1266 | [[ $sandbox ]] && sandbox 1267 | 1268 | # Run rules. 1269 | for rule in "${rest[@]}" 1270 | do 1271 | if [[ $batch || $interactive ]] 1272 | then 1273 | debug "Adding batch/interactive argument: $rule" 1274 | args_batch_interactive+=("$rule") 1275 | 1276 | elif [[ $rule = batch ]] 1277 | then 1278 | # Remaining arguments are passed to Emacs. 1279 | batch=true 1280 | elif [[ $rule = interactive ]] 1281 | then 1282 | # Remaining arguments are passed to Emacs. 1283 | interactive=true 1284 | 1285 | elif type -t "$rule" 2>/dev/null | grep function &>/dev/null 1286 | then 1287 | # Pass called-directly as $1 to indicate that the rule is 1288 | # being called directly rather than from a meta-rule. 1289 | $rule called-directly 1290 | elif [[ $rule = test ]] 1291 | then 1292 | # Allow the "tests" rule to be called as "test". Since "test" 1293 | # is a shell builtin, this workaround is required. 1294 | tests 1295 | else 1296 | error "Invalid rule: $rule" 1297 | fi 1298 | done 1299 | 1300 | # Batch/interactive rules. 1301 | [[ $batch ]] && batch 1302 | [[ $interactive ]] && interactive 1303 | 1304 | if [[ $errors -gt 0 ]] 1305 | then 1306 | log_color red "Finished with $errors errors." 1307 | else 1308 | success "Finished without errors." 1309 | fi 1310 | 1311 | exit $errors 1312 | -------------------------------------------------------------------------------- /manifest.scm: -------------------------------------------------------------------------------- 1 | (specifications->manifest 2 | '("emacs-eldev")) 3 | -------------------------------------------------------------------------------- /notes.org: -------------------------------------------------------------------------------- 1 | #+begin_src text :exports none 2 | About: 3 | 4 | org-web-track: 5 | A framework in Org Mode to assist users in managing data that changes over time from web pages and web APIs. 6 | #+end_src 7 | -------------------------------------------------------------------------------- /org-web-track.el: -------------------------------------------------------------------------------- 1 | ;;; org-web-track.el --- Web data tracking framework in Org Mode -*- lexical-binding: t -*- 2 | 3 | ;; Author: p-snow 4 | ;; Maintainer: p-snow 5 | ;; Version: 0.1.2-dev 6 | ;; Package-Requires: ((emacs "29.1") (request "0.3.0") (enlive "0.0.1") (gnuplot "0.8.1")) 7 | ;; Homepage: https://github.com/p-snow/org-web-track 8 | ;; Keywords: org, agenda, web, hypermedia 9 | 10 | 11 | ;; This file is not part of GNU Emacs 12 | 13 | ;; This program is free software: you can redistribute it and/or modify 14 | ;; it under the terms of the GNU General Public License as published by 15 | ;; the Free Software Foundation, either version 3 of the License, or 16 | ;; (at your option) any later version. 17 | 18 | ;; This program is distributed in the hope that it will be useful, 19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | ;; GNU General Public License for more details. 22 | 23 | ;; You should have received a copy of the GNU General Public License 24 | ;; along with this program. If not, see . 25 | 26 | 27 | ;;; Commentary: 28 | 29 | ;; Org Web Track provide an Org Mode framework that assists users in managing 30 | ;; their values of interest on a website or via a Web API. 31 | 32 | ;; Through the use of Org Web Track: 33 | ;; - Any location in the web page or any piece in the web API response can be an 34 | ;; item to track 35 | ;; - Users can monitor changes for the item and manage them using the facilities 36 | ;; of Org mode 37 | ;; - A set of items to track can be reviewed with their updated values in an Org 38 | ;; column view 39 | ;; - Users can extract an Org table displaying value changes and create a visual 40 | ;; graph using Gnuplot. 41 | 42 | 43 | ;;; Code: 44 | 45 | (require 'org) 46 | (require 'org-agenda) 47 | (require 'org-colview) 48 | (require 'org-plot) 49 | (require 'url-http) 50 | (require 'request) 51 | (require 'enlive) 52 | (require 'rx) 53 | 54 | ;;;; Variables 55 | 56 | (defvar org-web-track-value "TRACK_CURRENT_VALUE" 57 | "Property name for holding current value.") 58 | (put 'org-web-track-value 'label "CURRENT VALUE") 59 | 60 | (defvar org-web-track-prev-value "TRACK_PREVIOUS_VALUE" 61 | "Property name for holding previous value.") 62 | (put 'org-web-track-prev-value 'label "PREVIOUS") 63 | 64 | (defvar org-web-track-url "TRACK_URL" 65 | "Org property for a URL to access.") 66 | 67 | (defvar org-web-track-http-headers "TRACK_HTTP_HEADERS" 68 | "Org property for headers in HTTP request.") 69 | 70 | (defvar org-web-track-unix-socket "TRACK_UNIX_SOCKET" 71 | "Org property for a Unix Domain Socket path to connect.") 72 | 73 | (defvar org-web-track-updated "TRACK_LAST_UPDATED_TIME" 74 | "Property name for the date at which track value.") 75 | (put 'org-web-track-updated 'label "UPDATED TIME") 76 | 77 | (defvar org-web-track-update-timeout 20 78 | "Time out in second for accessing web site to get values.") 79 | 80 | (defvar org-web-track-value-column-format "%c [%p]" 81 | "Column format where current and previous values are placed in %c and %p.") 82 | 83 | ;;;; Customization 84 | 85 | (defgroup org-web-track nil 86 | "Options for `org-web-track'." 87 | :group 'org 88 | :link '(url-link "https://github.com/p-snow/org-web-track")) 89 | 90 | (defcustom org-web-track-selectors-alist nil 91 | "An alist of URL-MATCH and SELECTOR(S). 92 | 93 | URL-MATCH specifies the URL to which SELECTOR will be applied. SELECTOR is 94 | utilized to extract the desired value from the content of the URL. A single 95 | URL-MATCH links to one or more SELECTORS. Therefore, each element appears as 96 | \(URL-MATCH . SELECTOR) or (URL-MATCH SELECTORS...). 97 | 98 | URL-MATCH: 99 | URL-MATCH must be either a string or a function. The string is used as a regexp 100 | to determine the URL that match against it. The function takes one argument, a 101 | URL candidate, and must return non-nil if this selector can deal with the URL. 102 | 103 | SELECTOR: 104 | SELECTOR must be either a vector, a function or a string. 105 | 106 | If SELECTOR is a vector, it is assumed to represent a CSS selector that is used 107 | to determine the result value. The selection rules are as follows: the text of 108 | the selected tag will serve as the result value. 109 | 110 | id : [:main] 111 | class : [.content.home-page] 112 | tagname : [p.demo a] 113 | direct children : [.article > p] 114 | all nodes : [:section > *] 115 | 116 | org-web-track delegates CSS selector procedure to enlive package. For more 117 | details, please visit the website. 118 | 119 | enlive: https://github.com/zweifisch/enlive 120 | 121 | If SELECTOR is a function, it must accept a data object and return a value. 122 | 123 | The type of the data object depends on the MIME type of the HTTP response. If 124 | the MIME type is text/html, the data object is an HTML parse tree obtained from 125 | `libxml-parse-html-region'. Likewise, if the MIME type is application/xml, the 126 | data object will be an XML parse tree from `libxml-parse-xml-region', if the 127 | MIME type is application/json, an ELisp object from `json-parse-string' will be 128 | the data object, and if the MIME type is text/plain, the content itself will be 129 | the data object as a string. 130 | 131 | The return value of the function must be either a string, a number, or a list of 132 | those. If a list is returned, each element represents a tracking unit that will 133 | be compared over time. 134 | 135 | If SELECTOR is a string, it is assumed to be a shell command that should accept 136 | the HTTP response content as stdin and return a value as stdout." 137 | :type '(alist :key-type (string :tag "Regexp") 138 | :value-type 139 | (choice (vector :tag "A CSS selector") 140 | (string :tag "A shell command that processes HTTP response content") 141 | function)) 142 | :group 'org-web-track) 143 | 144 | (defcustom org-web-track-content-fetcher-alist nil 145 | "An alist of URL-MATCH and CONTENT-FETCHER. 146 | 147 | URL-MATCH specifies the URL for which CONTENT-FETCHER is 148 | responsible. If CONTENT-FETCHER is specified for the URL, 149 | org-web-track delegates the HTTP connection and content fetching 150 | to it and receives the content, which will then be applied to 151 | SELECTOR. 152 | 153 | CONTENT-FETCHER must be either a function or a string. 154 | 155 | If it is a function, it must accept a single argument - a URL. It 156 | should then return the content obtained by accessing the URL, 157 | presented as a string. If the content is anything other than an 158 | HTML, the return format has to be (MIME-TYPE . CONTENT), where 159 | the supported MIME-TYPE can be either \"text/html\" , 160 | \"application/xml\", \"application/json\" or \"text/plain\" as a 161 | string. 162 | 163 | If CONTENT-FETCHER is a string, it is interpreted as a shell 164 | command string. In the shell command, %s may appear, which is 165 | replaced with a URL at execution time. When %s is not present, 166 | the shell command can receive the URL via stdin. 167 | 168 | The shell command does not have a method to return the MIME type. 169 | Therefore, CONTENT-FETCHER, which returns a content other than 170 | HTML, needs to be implemented as a function." 171 | :type '(alist :key-type (string :tag "Regexp") 172 | :value-type function) 173 | :group 'org-web-track) 174 | 175 | (defcustom org-web-track-files nil 176 | "The files to be used in `org-web-track-agenda-columns'. 177 | 178 | Its value must be either a list of strings representing file paths 179 | or a function that returns the same data structure." 180 | :type '(choice 181 | (repeat :tag "List of files" file) 182 | (function)) 183 | :group 'org-web-track) 184 | 185 | (defcustom org-web-track-use-curl 186 | (not (null (executable-find "curl"))) 187 | "Whether to use cURL as the fetching backend instead of `url-retrieve'. 188 | 189 | If non-nil, the cURL program at a searchable location will be 190 | used to fetch web content. Otherwise, the Elisp function 191 | `url-retrieve' will be used. 192 | 193 | This can be a string, which indicates the path for the cURL 194 | executable to be used. 195 | 196 | Note that even if this is nil, the cURL program will still be 197 | used when the tracking item prefers to access the Unix Socket 198 | Server (which means the org entry has 199 | `org-web-track-set-unix-socket' property), as `url-retrieve' 200 | cannot access the Unix Socket Server." 201 | :group 'org-web-track 202 | :package-version '(org-web-track . "0.0.3") 203 | :type 'boolean) 204 | 205 | (defcustom org-web-track-default-http-headers 206 | (list (string-trim (url-http-user-agent-string))) 207 | "Default HTTP http-headers that are sent in every HTTP request session." 208 | :group 'org-web-track 209 | :package-version '(org-web-track . "0.1.0") 210 | :type '(list (string :tag "Field name and value pair"))) 211 | 212 | (defcustom org-web-track-trim-values t 213 | "Whether to trim retrieved values. 214 | 215 | Non-nil means to remove preceding and trailing whitespace 216 | characters from the values returned by each selector." 217 | :group 'org-web-track 218 | :package-version '(org-web-track . "0.1.0") 219 | :type 'boolean) 220 | 221 | (defcustom org-web-track-report-date-format nil 222 | "Date format in the report created by `org-web-track-report'. 223 | 224 | This format string will be assigned to `format-time-string'. If 225 | it is not a string, ISO 8601 date format (%+4Y-%m-%d) will be 226 | used." 227 | :type 'string 228 | :package-version '(org-web-track . "0.1.0") 229 | :group 'org-web-track) 230 | 231 | (defcustom org-web-track-item-column-width 0 232 | "0 means unspecified." 233 | :type 'natnum 234 | :group 'org-web-track) 235 | 236 | (defcustom org-web-track-update-column-width 0 237 | "0 means unspecified." 238 | :type 'natnum 239 | :group 'org-web-track) 240 | 241 | 242 | (defun org-web-track-files () 243 | "Return a list of files that contain tracking entries." 244 | (pcase org-web-track-files 245 | ((and (pred functionp) fun) (funcall fun)) 246 | ((and (pred listp) li) li))) 247 | 248 | ;;;###autoload 249 | (defun org-web-track-setup-entry (url) 250 | "Initialize the entry at point by setting URL to `org-web-track-url'. 251 | 252 | If point is positioned before the first org heading, insert a new one above it 253 | initially. 254 | 255 | After the URL has been set, try to retrieve a valuees if there is 256 | an appropriate selector in `org-web-track-selectors-alist'." 257 | (interactive (list (when (or (null (org-entry-get (point) org-web-track-url)) 258 | (y-or-n-p (format "Are you sure of overwriting existing %s property?" org-web-track-url))) 259 | (read-string "URL: ")))) 260 | (when (stringp url) 261 | (when (org-before-first-heading-p) 262 | (org-insert-heading)) 263 | (org-entry-put (point) org-web-track-url url) 264 | (org-web-track-update-entry))) 265 | 266 | ;;;###autoload 267 | (defun org-web-track-set-http-headers (epom http-headers) 268 | "Set HTTP-HEADERS for the entry at EPOM. 269 | 270 | If called interactively, a minibuffer appears and the user is 271 | required to submit HTTP headers on it for the entry at point. 272 | 273 | The field name and value in HTTP headers must be delimtted by 274 | colon and multiple headers must be separated by a newline. When 275 | users write HTTP headers in the minibuffer, they should use `C-q' 276 | `C-j', instead of RET, for a newline. This is because pressing RET 277 | triggers an exit in the minibuffer." 278 | (interactive (let* ((headers-text (org-entry-get-multivalued-property nil org-web-track-http-headers)) 279 | (headers-text-anew (read-from-minibuffer "" (string-join headers-text "\n")))) 280 | (list nil headers-text-anew))) 281 | (apply #'org-entry-put-multivalued-property 282 | epom org-web-track-http-headers 283 | (split-string http-headers "[\n\r]+" t (rx space)))) 284 | 285 | ;;;###autoload 286 | (defun org-web-track-set-unix-socket (epom unix-socket) 287 | "Set UNIX-SOCKET for the entry at EPOM. 288 | 289 | If called interactively, a minibuffer appears and the user is 290 | required to input a Unix socket path for the entry at point." 291 | (interactive (let* ((unix-sock (org-entry-get nil org-web-track-unix-socket)) 292 | (unix-sock-anew (read-file-name "Unix socket: " nil nil nil unix-sock))) 293 | (list nil unix-sock-anew))) 294 | (org-entry-put epom org-web-track-unix-socket unix-socket)) 295 | 296 | ;;;###autoload 297 | (defun org-web-track-update-entry (&optional marker) 298 | "Update the tracking item at MARKER. 299 | 300 | If called interactively, update the org entry at point. 301 | 302 | This command looks up the current values and updates `org-web-track-value' 303 | and `org-web-track-prev-value' if the values have been changed, 304 | then logs them using org's logging feature. The placement of logs respects 305 | the configuration in the variable `org-log-into-drawer'." 306 | (interactive (list (point-marker))) 307 | (when-let* ((track-url (or (rx-let ((url-re (seq (regexp "https?://") (+ graph)))) 308 | (pcase (org-entry-get marker org-web-track-url) 309 | ((rx "[[" (let link url-re) "][" (* print) "]]") link) 310 | ((rx "[[" (let link url-re) "]]") link) 311 | ((rx (let url url-re)) url))) 312 | (user-error "No valid %s property" org-web-track-url))) 313 | (selectors 314 | (or (ensure-list 315 | (assoc-default track-url org-web-track-selectors-alist 316 | (lambda (car key) 317 | (pcase car 318 | ((and (pred functionp) match-fun) 319 | (funcall match-fun key)) 320 | ((and (pred stringp) match-str) 321 | (string-match-p match-str key)))))) 322 | (user-error "No selector found responsible for %s in org-web-track-selectors-alist" 323 | track-url))) 324 | (updates 325 | (if-let* ((fetcher-cdr (assoc-default track-url org-web-track-content-fetcher-alist 326 | (lambda (car key) (string-match-p car key)))) 327 | (content (pcase fetcher-cdr 328 | ((or (and (pred functionp) 329 | fetcher-fun) 330 | (and `(,(pred functionp) . ,_) 331 | (let fetcher-fun (car fetcher-cdr)))) 332 | (funcall fetcher-fun track-url)) 333 | ((and (pred stringp) fetcher-cmd) 334 | (with-temp-buffer 335 | (when (= 0 (call-shell-region (insert track-url) nil 336 | (format fetcher-cmd (shell-quote-argument track-url)) 337 | t t)) 338 | (buffer-substring-no-properties (point-min) (point-max)))))))) 339 | (apply #'org-web-track--apply-selectors 340 | (pcase content 341 | ((and (pred stringp) str-cnt) `("text/html" ,str-cnt ,selectors)) 342 | (`(,mtype . ,cnt) 343 | `(,mtype ,(or (and (listp cnt) 344 | (car cnt)) 345 | cnt) 346 | ,selectors)))) 347 | (org-web-track-retrieve-values track-url 348 | selectors 349 | (org-entry-get-multivalued-property marker org-web-track-http-headers) 350 | (org-entry-get marker org-web-track-unix-socket)))) 351 | (current-time (format-time-string (org-time-stamp-format t t))) 352 | (org-log-note-headings (append '((update . "Update %-12s %t")) 353 | org-log-note-headings))) 354 | (let ((incumbent-values 355 | (or (org-entry-get-multivalued-property marker org-web-track-value) 356 | (make-list (length updates) " ")))) 357 | (when (or (null incumbent-values) 358 | (and (not (equal updates incumbent-values)) 359 | (apply #'org-entry-put-multivalued-property 360 | marker org-web-track-prev-value incumbent-values))) 361 | (apply #'org-entry-put-multivalued-property 362 | marker org-web-track-value updates) 363 | (let ((inhibit-message t)) ; inhibit "Note Stored" message 364 | (org-with-point-at marker 365 | (org-add-log-setup 'update 366 | ;; work around for stuck process in 367 | ;; string conversion at `org-store-log-note' 368 | (replace-regexp-in-string "\\(?:%20\\([DSTUdstu]\\)\\)" "_\\1" 369 | (org-entry-get (point) org-web-track-value)) 370 | nil 'state current-time) 371 | (run-hooks 'post-command-hook))) 372 | (org-entry-put marker org-web-track-updated current-time) 373 | (when (called-interactively-p 'any) 374 | (message "Updated: %s" (org-entry-get marker org-web-track-value))) 375 | marker)))) 376 | 377 | ;;;###autoload 378 | (defun org-web-track-update-files () 379 | "Update all track items in variable `org-web-track-files'. 380 | 381 | Return a list of markers pointing to items where the value has been updated." 382 | (interactive) 383 | (delq nil (org-map-entries (lambda () 384 | (org-web-track-update-entry (point-marker))) 385 | (format "%s={.+}" org-web-track-url) 386 | (org-web-track-files)))) 387 | 388 | (defun org-web-track-retrieve-values (url selectors &optional http-headers unix-socket) 389 | "Retrieve values using URL, SELECTORS, HTTP-HEADERS and UNIX-SOCKET. 390 | 391 | If an optional argument UNIX-SOCKET is provided as a path for a Unix Domain 392 | Socket to connect, the function will attempt to access the HTTP socket server 393 | running on the local machine instead of the WWW server." 394 | (pcase-let ((request-backend (if (or org-web-track-use-curl unix-socket) 395 | 'curl 'url-retrieve)) 396 | (request-curl (if (stringp org-web-track-use-curl) 397 | org-web-track-use-curl 398 | (default-value 'request-curl))) 399 | (`(,request-curl-options . ,url-request-extra-headers) 400 | (let ((header-list (append org-web-track-default-http-headers 401 | (when (listp http-headers) 402 | http-headers)))) 403 | `(,(mapcar (lambda (header) 404 | (format "-H %s" header)) 405 | header-list) 406 | . ,(mapcar (lambda (header) 407 | (split-string header (rx (seq ":" (0+ space))))) 408 | header-list)))) 409 | (values nil)) 410 | (request url 411 | :sync t 412 | :timeout org-web-track-update-timeout 413 | :unix-socket unix-socket 414 | :success 415 | (cl-function 416 | (lambda (&key response &allow-other-keys) 417 | (setq values 418 | (org-web-track--apply-selectors 419 | (request-response-header response "content-type") 420 | (request-response-data response) 421 | selectors)))) 422 | :error 423 | (cl-function 424 | (lambda (&key response &allow-other-keys) 425 | (when (eq (request-response-symbol-status response) 'timeout) 426 | (setq values nil)) 427 | (message "HTTP error occurred: %s\n URL: %s" 428 | (request-response-error-thrown response) 429 | url))) 430 | :complete 431 | (cl-function 432 | (lambda (&key data &allow-other-keys) 433 | (unless (seq-some 'stringp values) 434 | (message "No value was retrieved\n URL: %s" url)) 435 | data))) 436 | values)) 437 | 438 | (defmacro org-web-track--with-content-buffer (content &rest body) 439 | "Execute BODY in the temporary buffer where CONTENT is inserted." 440 | (declare (indent 1)) 441 | `(with-temp-buffer 442 | (set-buffer-multibyte t) 443 | (insert ,content) 444 | ,@body)) 445 | 446 | (defun org-web-track--apply-selectors (content-type content selectors) 447 | "Apply SELECTORS to CONTENT where HTTP Content-Type is CONTENT-TYPE." 448 | (pcase-let* ((`(,mime-subtype . ,decoded-content) 449 | (save-match-data 450 | (and (string-match 451 | (rx (seq (or (seq "application/" (group-n 1 (or "json" "xml"))) 452 | (seq "text/" (group-n 1 (or "html" "plain")))) 453 | (opt (regexp url-mime-content-type-charset-regexp)))) 454 | content-type) 455 | (cons (intern (match-string 1 content-type)) 456 | (decode-coding-string content 457 | (car (member 458 | (intern (downcase (or (match-string 2 content-type) 459 | "utf-8"))) 460 | (coding-system-list))))))))) 461 | (ensure-list 462 | (flatten-tree 463 | (mapcar 464 | (lambda (selector) 465 | (mapcar (lambda (val) 466 | (let ((crude-val (pcase val 467 | ((and (pred stringp) str) 468 | (if org-web-track-trim-values 469 | (string-trim val) str)) 470 | ((and (pred numberp) num) 471 | (number-to-string num)) 472 | (_ "")))) 473 | ;; Replace an empty string with a single space 474 | ;; since `org-entry-put-multivalued-property' does not accept an empty string 475 | (if (string-empty-p crude-val) 476 | " " crude-val))) 477 | (ensure-list 478 | (pcase `(,mime-subtype . ,selector) 479 | (`(,_ . ,(and (pred stringp) selector-command)) 480 | (org-web-track--with-content-buffer content 481 | (when (= 0 (shell-command-on-region (point-min) (point-max) 482 | selector-command t t)) 483 | (buffer-substring-no-properties (point-min) (point-max))))) 484 | (`(,subtype . ,(and (pred functionp) selector-func)) 485 | (funcall selector-func 486 | (cl-case subtype 487 | (json (json-parse-string decoded-content :object-type 'alist)) 488 | (html (org-web-track--with-content-buffer decoded-content 489 | (libxml-parse-html-region))) 490 | (xml (org-web-track--with-content-buffer decoded-content 491 | (libxml-parse-xml-region))) 492 | (plain decoded-content)))) 493 | (`(html . ,(and (pred vectorp) css-selector)) 494 | (enlive-text (enlive-query (enlive-parse decoded-content) 495 | css-selector))))))) 496 | ;; ensure that SELECTORS is a list, except in the case of lambda 497 | (if (or (nlistp selectors) 498 | (eq (car selectors) 'lambda)) 499 | (list selectors) 500 | selectors)))))) 501 | 502 | ;;;###autoload 503 | (defun org-web-track-report (&optional plot) 504 | "Insert an Org table displaying values in chronological order, then PLOT a graph. 505 | 506 | If called with the \\[universal-argument] prefix, the table will be inserted 507 | with #+PLOT special headers, which are recognizable for org-plot to create a 508 | graph. After that, the graph will be display automatically. Note that this 509 | feature requires the Gnuplot program and the Emacs gnuplot package." 510 | (interactive "P") 511 | (let ((table-rows)) 512 | (org-with-wide-buffer 513 | (org-save-outline-visibility t 514 | (org-back-to-heading t) 515 | (let* ((case-fold-search t) 516 | (subtree-end (save-excursion 517 | (org-next-visible-heading 1) 518 | (point))) 519 | (re (concat (rx (or "Update" "Track") (+ space) 520 | "\"" (group (+ not-newline)) "\"" 521 | (+ space) (opt "on") (* space)) 522 | org-ts-regexp-inactive))) 523 | (while (re-search-forward re subtree-end t) 524 | (push `(,(encode-time (parse-time-string (match-string-no-properties 2))) 525 | ,@(mapcar #'org-entry-restore-space (split-string (match-string-no-properties 1)))) 526 | table-rows))))) 527 | (when table-rows 528 | (save-excursion 529 | (let ((num-column (1- (apply 'max (mapcar #'length table-rows)))) 530 | (format-string (or org-web-track-report-date-format "%Y-%m-%d"))) 531 | (sort table-rows 532 | (pcase-lambda (`(,time-a ,_) `(,time-b ,_)) 533 | (time-less-p time-a time-b))) 534 | (when (equal plot '(4)) 535 | (insert (format "#+PLOT: ind:1 deps:%s with:boxes type:2d\n" 536 | (cl-loop for i from 2 below (+ 2 num-column) 537 | collect i))) 538 | (insert "#+PLOT: set:\"xdata time\"\n") 539 | (insert (format "#+PLOT: set:\"timefmt '%s'\"\n" format-string)) 540 | (insert (apply #'format "#+PLOT: set:\"xrange ['%s':'%s']\"\n" 541 | (mapcar (apply-partially 542 | #'format-time-string "%F") 543 | `(,(time-add (car (first table-rows)) (* -60 60 24)) 544 | ,(time-add (caar (last table-rows)) (* 60 60 24))))))) 545 | (insert "|DATE") 546 | (cl-dotimes (num num-column) 547 | (insert (format "|VALUE %d" (1+ num)))) 548 | (insert "\n|--\n") 549 | (mapc (pcase-lambda (`(,time . ,values)) 550 | (insert (concat "| " (format-time-string format-string time))) 551 | (mapc (lambda (value) 552 | (insert (concat "| " 553 | (if (equal plot '(4)) 554 | (org-web-track--extract-number value) 555 | value)))) 556 | values) 557 | (insert " |\n")) 558 | table-rows) 559 | (org-table-align))) 560 | (when (and (equal plot '(4)) 561 | (called-interactively-p 'any) 562 | (fboundp 'org-plot/gnuplot)) 563 | (org-plot/gnuplot))))) 564 | 565 | (defun org-web-track--extract-number (string) 566 | "Extract an integer or floating-point number representation from STRING." 567 | (let ((string-sans-comma (replace-regexp-in-string "\\([0-9]\\),\\([0-9]\\)" "\\1\\2" string))) 568 | (and (string-match "[-+]?\\([0-9]*\\.[0-9]+\\|[0-9]+\\.?[0-9]*\\)" string-sans-comma) 569 | (match-string 0 string-sans-comma)))) 570 | 571 | (defun org-web-track-agenda-update () 572 | "Update the tracking item in `org-agenda-mode'. 573 | 574 | This command provides a way to invoke `org-web-track-update-entry' 575 | after `org-web-track-agenda-columns'." 576 | (interactive) 577 | (or (eq major-mode 'org-agenda-mode) (user-error "Not in agenda")) 578 | (org-agenda-check-type t 'agenda 'todo 'tags 'search) 579 | (org-agenda-check-no-diary) 580 | (org-agenda-redo-all) 581 | (org-agenda-maybe-loop 582 | #'org-web-track-agenda-update nil nil nil 583 | (let* ((marker (or (org-get-at-bol 'org-marker) 584 | (org-agenda-error))) 585 | (buffer (marker-buffer marker)) 586 | (pos (marker-position marker))) 587 | (set-marker-insertion-type marker t) 588 | (org-with-remote-undo buffer 589 | (with-current-buffer buffer 590 | (widen) 591 | (org-fold-show-all) 592 | (goto-char pos) 593 | (funcall-interactively #'org-web-track-update-entry)))))) 594 | 595 | (defun org-web-track-display-values (column-title values) 596 | "Modify the display of column VALUES for COLUMN-TITLE to be more understandable. 597 | 598 | This function is designed to be set for 599 | `org-columns-modify-value-for-display-function'." 600 | (and (org-entry-get (point) org-web-track-url) 601 | (string= column-title 602 | (format-spec org-web-track-value-column-format 603 | `((?p . ,(get 'org-web-track-prev-value 'label)) 604 | (?c . ,(get 'org-web-track-value 'label))))) 605 | (string= values 606 | (org-entry-get (point) org-web-track-value)) 607 | (org-web-track-current-changes (point)))) 608 | 609 | (defun org-web-track-current-changes (&optional pom format separator) 610 | "Return the current data change on the item at POM using FORMAT and SEPARATOR. 611 | 612 | If POM is nil, a return value of `point' is used. 613 | FORMAT defines how to describe the current change for a single target and should 614 | contain %p and %c as placeholders for the previous value and current value, 615 | respectively. 616 | SEPARATOR is used in between changes for multiple targets." 617 | (let (chnages) 618 | (cl-do ((curr-vals (org-entry-get-multivalued-property (or pom (point)) org-web-track-value) (cdr curr-vals)) 619 | (prev-vals (org-entry-get-multivalued-property (or pom (point)) org-web-track-prev-value) (cdr prev-vals))) 620 | ((not (or curr-vals prev-vals)) (string-join (nreverse chnages) (or separator ", "))) 621 | (push (format-spec (or format org-web-track-value-column-format) 622 | `((?p . ,(or (car prev-vals) "N/A")) 623 | (?c . ,(or (car curr-vals) "N/A")))) 624 | chnages)))) 625 | 626 | (defun org-web-track-columns-format () 627 | "Return columns format for `org-columns' for org-web-track." 628 | (apply #'format "%%%sITEM %%%s%s(%s) %%%s(%s)" 629 | `(,@(mapcar (lambda (w) (if (= 0 w) "" (format "%d" w))) 630 | `(,org-web-track-item-column-width 631 | ,org-web-track-update-column-width)) 632 | ,org-web-track-value 633 | ,(format-spec org-web-track-value-column-format 634 | `((?p . ,(get 'org-web-track-prev-value 'label)) 635 | (?c . ,(get 'org-web-track-value 'label)))) 636 | ,org-web-track-updated 637 | ,(get 'org-web-track-updated 'label)))) 638 | 639 | ;;;###autoload 640 | (defun org-web-track-columns () 641 | "Display a column view specialized for tracking items. 642 | 643 | This command invokes `org-columns' with `org-web-track-columns-format' 644 | to display current changes on tracking items along with the updated time." 645 | (interactive) 646 | (let ((org-columns-modify-value-for-display-function 647 | 'org-web-track-display-values)) 648 | (org-columns nil (org-web-track-columns-format)))) 649 | 650 | ;;;###autoload 651 | (defun org-web-track-agenda-columns () 652 | "Display a agenda column view specialized for tracking items. 653 | 654 | This command invokes `org-agenda-columns' with `org-web-track-columns-format' 655 | to display current changes on tracking items in variable `org-web-track-files' 656 | along with the updated time." 657 | (interactive) 658 | (let ((org-columns-modify-value-for-display-function 659 | 'org-web-track-display-values) 660 | (org-columns-default-format-for-agenda (org-web-track-columns-format)) 661 | (org-agenda-files (org-web-track-files)) 662 | (org-agenda-sorting-strategy '((tags user-defined-up))) 663 | (org-agenda-cmp-user-defined 'org-web-track-cmp-updated-time) 664 | (org-agenda-view-columns-initially t)) 665 | (org-tags-view nil (format "%s={.+}" org-web-track-url)))) 666 | 667 | (defun org-web-track-cmp-updated-time (a b) 668 | "Compare A and B with respect to their `org-web-track-updated' property. 669 | 670 | Return -1 if A has an earlier time stamp indicating that the track item was 671 | updated before B. 672 | Return +1 if B is earlier, and nil if they are equal. 673 | 674 | This function is intended to be set for `org-agenda-cmp-user-defined'." 675 | (cl-labels ((updated-time (ent) 676 | (ignore-errors 677 | (encode-time 678 | (org-parse-time-string 679 | (org-entry-get (get-text-property 0 'org-hd-marker ent) 680 | org-web-track-updated)))))) 681 | (let ((ta (updated-time a)) 682 | (tb (updated-time b))) 683 | (cond ((if ta (and tb (time-less-p ta tb)) tb) -1) 684 | ((if tb (and ta (time-less-p tb ta)) ta) +1))))) 685 | 686 | (provide 'org-web-track) 687 | 688 | ;;; org-web-track.el ends here 689 | -------------------------------------------------------------------------------- /org-web-track.info: -------------------------------------------------------------------------------- 1 | This is org-web-track.info, produced by .texi2any-real version 7.1.1 2 | from org-web-track.texi. 3 | 4 | INFO-DIR-SECTION Emacs 5 | START-INFO-DIR-ENTRY 6 | * Org Web Track: (org-web-track). Web data tracking framework in Org Mode. 7 | END-INFO-DIR-ENTRY 8 | 9 |  10 | File: org-web-track.info, Node: Top, Next: Overview, Up: (dir) 11 | 12 | org-web-track.el - Web data tracking framework in Org Mode 13 | ********************************************************** 14 | 15 | Org Web Track provides an Org Mode framework that assists users in 16 | managing their values of interest on a website or via a Web API. 17 | 18 | * Menu: 19 | 20 | * Overview:: 21 | * Installation:: 22 | * Basic Usage:: 23 | * Extended Examples:: 24 | * Q&A:: 25 | * License:: 26 | * Indices:: 27 | 28 | -- The Detailed Node Listing -- 29 | 30 | Overview 31 | 32 | * Retrieving data:: 33 | 34 | Installation 35 | 36 | * MELPA package:: 37 | 38 | Basic Usage 39 | 40 | * Defining Tracking Items:: 41 | * Updating Values:: 42 | * Displaying Column View:: 43 | * Reporting and Creating Graph:: 44 | 45 | Defining Tracking Items 46 | 47 | * Sending Additional HTTP Headers:: 48 | * Dealing with Dinamic Website:: 49 | * Accessing Unix Domain Socket Server:: 50 | 51 | Extended Examples 52 | 53 | * Automatic Bulk Updating and Email Notifications:: 54 | 55 | Q&A 56 | 57 | * Network Certificate Issue:: 58 | 59 | Indices 60 | 61 | * Function index:: 62 | * Variable index:: 63 | * Concept index:: 64 | 65 | 66 |  67 | File: org-web-track.info, Node: Overview, Next: Installation, Prev: Top, Up: Top 68 | 69 | 1 Overview 70 | ********** 71 | 72 | Through the use of Org Web Track: 73 | • Any location in the web page or any piece in the web API response 74 | can be an item to track 75 | • Users can monitor changes for the item and manage them using the 76 | facilities of Org mode 77 | • A set of items to track can be reviewed with their updated values 78 | in an Org column view 79 | • Users can extract an Org table displaying value changes and create 80 | a visual graph using Gnuplot. 81 | 82 | * Menu: 83 | 84 | * Retrieving data:: 85 | 86 |  87 | File: org-web-track.info, Node: Retrieving data, Up: Overview 88 | 89 | 1.1 Retrieving data 90 | =================== 91 | 92 | When users specify which snippet of data to track on web pages or web 93 | APIs, the following methods are available: 94 | 95 | • CSS selectors, which are applied against the source code of the web 96 | page 97 | • Elisp functions, which receive a DOM object or a JSON object from a 98 | web page or a web API and are expected to return a desired value 99 | from the argument 100 | • Shell commands, which take a page source or an API response as 101 | STDIN and are expected to print a desired value to STDOUT 102 | 103 |  104 | File: org-web-track.info, Node: Installation, Next: Basic Usage, Prev: Overview, Up: Top 105 | 106 | 2 Installation 107 | ************** 108 | 109 | Requirements: 110 | • Emacs 29.1 or higher 111 | • request.el (https://github.com/tkf/emacs-request) v0.3.2 112 | • enlive (https://github.com/zweifisch/enlive) v0.0.1 113 | 114 | * Menu: 115 | 116 | * MELPA package:: 117 | 118 |  119 | File: org-web-track.info, Node: MELPA package, Up: Installation 120 | 121 | 2.1 MELPA package 122 | ================= 123 | 124 | Org Web Track can be installed from MELPA using package.el as follows: 125 | 126 | 1. Add melpa to package-archives 127 | (add-to-list 'package-archives 128 | '("melpa" . "https://melpa.org/packages/") 129 | t) 130 | 2. Refresh package contents 131 | M-x package-refresh-contents 132 | 3. Install Org Web Track 133 | M-x package-install 134 | 135 | and select org-web-track 136 | 137 |  138 | File: org-web-track.info, Node: Basic Usage, Next: Extended Examples, Prev: Installation, Up: Top 139 | 140 | 3 Basic Usage 141 | ************* 142 | 143 | In this section, the basic Org Web Track mechanism and fundamental 144 | command usage are described. 145 | 146 | * Menu: 147 | 148 | * Defining Tracking Items:: 149 | * Updating Values:: 150 | * Displaying Column View:: 151 | * Reporting and Creating Graph:: 152 | 153 |  154 | File: org-web-track.info, Node: Defining Tracking Items, Next: Updating Values, Up: Basic Usage 155 | 156 | 3.1 Defining Tracking Items 157 | =========================== 158 | 159 | Before setting up each tracking item, users need to define 160 | ‘org-web-track-selectors-alist’, whose element consists of two 161 | components: URL-MATCH and SELECTOR. Each element is responsible for 162 | selecting a value for the specific URL that matches URL-MATCH, a regexp. 163 | The SELECTOR will then be applied to the content of the HTTP response at 164 | the URL to extract the resulting value. 165 | 166 | A single URL-MATCH is associated with one or more SELECTORS. 167 | Therefore, the element of the variable appears as either (URL-MATCH . 168 | SELECTOR) or (URL-MATCH SELECTORS...). Below is a typical example of 169 | how to set the variable: 170 | 171 | (setq org-web-track-selectors-alist '(("example\\.com/product" . 172 | [.final-price]))) 173 | 174 | This code define how to extract product prices at the site 175 | "example.com". In the site, the price posits in the tag whose class is 176 | "final-price". This case, SELECTOR is CSS selector, one of available 177 | formats. SELECTOR can be more than that. Please refer to the 178 | documentation of ‘org-web-track-selectors-alist’ for more detail. 179 | 180 | This code dictates how to extract product prices from the site 181 | "example.com". On the site, the price is located within a tag whose 182 | class is "final-price". In this case, SELECTOR is a vector, which 183 | signifies a CSS selector. Besides this, SELECTOR can also be a function 184 | or a string. This means it can represent an Elisp procedure or a shell 185 | command respectively. For more details, please refer to the 186 | documentation of ‘org-web-track-selectors-alist’. 187 | 188 | After appropriately defining ‘org-web-track-selectors-alist’, users 189 | can set up each specific tracking item by calling 190 | ‘org-web-track-setup-entry’ on the desired org entry or before the first 191 | heading to create a new one in the org buffer. Users will be prompted 192 | to input the tracking URL, and then the updated value will be retrieved, 193 | stored, and displayed in the echo area according to the aforementioned 194 | settings. 195 | 196 | * Book ABC 197 | :PROPERTIES: 198 | :TRACK_URL: https://example.com/products/book-abc.html 199 | :TRACK_CURRENT_VALUE: $30 200 | :TRACK_LAST_UPDATED_TIME: [2024-07-18 Thu 16:57] 201 | :END: 202 | :LOGBOOK: 203 | - Update "$30" [2024-07-18 Thu 16:57] 204 | :END: 205 | 206 | Some practical tracking item examples for specific real services are 207 | showcased on the Wiki page of the project website at 208 | . 209 | 210 | * Menu: 211 | 212 | * Sending Additional HTTP Headers:: 213 | * Dealing with Dinamic Website:: 214 | * Accessing Unix Domain Socket Server:: 215 | 216 |  217 | File: org-web-track.info, Node: Sending Additional HTTP Headers, Next: Dealing with Dinamic Website, Up: Defining Tracking Items 218 | 219 | 3.1.1 Sending Additional HTTP Headers 220 | ------------------------------------- 221 | 222 | In an HTTP request message, a client can include a set of information 223 | known as an HTTP header, each element presented in a key-value pair 224 | format. This allows the client to send metadata to the server for 225 | various purposes, such as authentication or user identification. 226 | 227 | In Org Web Track, users can specify HTTP headers in a couple of ways. 228 | First, they can set a variable ‘org-web-track-default-http-headers’ that 229 | is applied to every HTTP request. Second, they can execute a command 230 | ‘org-web-track-set-http-headers’ that sets specific HTTP headers for 231 | individual entries. 232 | 233 |  234 | File: org-web-track.info, Node: Dealing with Dinamic Website, Next: Accessing Unix Domain Socket Server, Prev: Sending Additional HTTP Headers, Up: Defining Tracking Items 235 | 236 | 3.1.2 Dealing with Dinamic Website 237 | ---------------------------------- 238 | 239 | The HTTP request backend of org-web-track, either cURL or url-retrieve, 240 | lacks the ability to read a dynamic website like a JS-rendered page. To 241 | work around this issue, org-web-track employs a delegation mechanism for 242 | fetching content. CONTENT-FETCHER in the 243 | org-web-track-content-fetcher-alist is used for this purpose. Users are 244 | free to implement any procedure using libraries such as Selenium or 245 | WebDriver in it. 246 | 247 |  248 | File: org-web-track.info, Node: Accessing Unix Domain Socket Server, Prev: Dealing with Dinamic Website, Up: Defining Tracking Items 249 | 250 | 3.1.3 Accessing Unix Domain Socket Server 251 | ----------------------------------------- 252 | 253 | While org-web-track primarily focuses on the WWW server as the access 254 | target, users also have the option to connect to a Unix Domain Socket 255 | server, which provides HTTP services mainly on a local machine. A 256 | simple example of a Unix Socket server implementation complying with the 257 | org-web-track framework can be found at 258 | . Using this feature, 259 | non-HTTP services, such as Unix shell commands, can be effectively 260 | utilized within the org-web-track framework. 261 | 262 | Users who want to access the Unix Domain Socket server must set the 263 | socket's path by calling ‘org-web-track-set-unix-socket’ at the desired 264 | tracking item. When this feature is active, the value of the variable 265 | ‘org-web-track-use-curl’ will not be respected. The cURL program will 266 | implicitly be used as the fetching backend since url-retrieve cannot 267 | access the Unix Socket Server. 268 | 269 |  270 | File: org-web-track.info, Node: Updating Values, Next: Displaying Column View, Prev: Defining Tracking Items, Up: Basic Usage 271 | 272 | 3.2 Updating Values 273 | =================== 274 | 275 | The simplest way to update the value is to call 276 | ‘org-web-track-update-entry’ on the desired org entry. If the retrieved 277 | value is updated compared to the last value, the updated value will be 278 | stored as the TRACK_CURRENT_VALUE org property; otherwise, the entry 279 | will remain unchanged. 280 | 281 | Alternatively, bulk updating is supported. To enable bulk updating, 282 | users must first define ‘org-web-track-files’. This variable should be 283 | a list of files in which all tracking items, identified by having the 284 | TRACK_URL property, are selected for bulk updating. To perform bulk 285 | updating, call ‘org-web-track-update-files’. 286 | 287 |  288 | File: org-web-track.info, Node: Displaying Column View, Next: Reporting and Creating Graph, Prev: Updating Values, Up: Basic Usage 289 | 290 | 3.3 Displaying Column View 291 | ========================== 292 | 293 | Column view in org-mode is a feature that displays properties in a 294 | table, providing a clear and comprehensive perspective. org-web-track 295 | offers a specialized column view where updated values are juxtaposed 296 | with their previous values for tracking items. To display the column 297 | view, call ‘org-web-track-columns’ in org buffer. 298 | 299 | If tracking items are scattered across many files, 300 | ‘org-web-track-agenda-columns’ is useful as all tracking items in the 301 | aforementioned ‘org-web-track-files’ are gathered in the agenda column 302 | view. Users can also update any item in the agenda column view by 303 | calling ‘org-web-track-agenda-update’. 304 | 305 |  306 | File: org-web-track.info, Node: Reporting and Creating Graph, Prev: Displaying Column View, Up: Basic Usage 307 | 308 | 3.4 Reporting and Creating Graph 309 | ================================ 310 | 311 | All updated values from the past are logged in the entry using the 312 | existing org log note feature. Log notes have a fixed format and are 313 | placed in a drawer only if ‘org-log-into-drawer’ is non-nil. 314 | 315 | ‘org-web-track-report’ creates an Org table where all log note values 316 | in the current Org entry are listed in ascending order of time, showing 317 | the transition of values over time. If called with C-u prefix, the 318 | command creates a visual graph using Gnuplot. Note that creating a 319 | graph requires the Gnuplot Emacs package and Gnuplot itself. 320 | 321 |  322 | File: org-web-track.info, Node: Extended Examples, Next: Q&A, Prev: Basic Usage, Up: Top 323 | 324 | 4 Extended Examples 325 | ******************* 326 | 327 | In this section, examples of how to utilize ‘org-web-track’ extensively 328 | are showcased. 329 | 330 | * Menu: 331 | 332 | * Automatic Bulk Updating and Email Notifications:: 333 | 334 |  335 | File: org-web-track.info, Node: Automatic Bulk Updating and Email Notifications, Up: Extended Examples 336 | 337 | 4.1 Automatic Bulk Updating and Email Notifications 338 | =================================================== 339 | 340 | While automatic updating may be ideal in certain situations, Org Web 341 | Track refrains from providing this feature directly to prevent potential 342 | data violations. However, users can enable automatic updating by 343 | calling ‘org-web-track-update-entry’ or ‘org-web-track-update-files’ 344 | from Elisp code. Below is an example implementation of automatic 345 | updates with email notifications scheduled for midnight. 346 | 347 | (defun exp/email-updated () 348 | "Check for updates on all tracking items in `org-web-track-files' 349 | and email me the updated list of items formatted as requested." 350 | (let* ((message-kill-buffer-on-exit t) 351 | (mail-msg (mapconcat 352 | (lambda (chg) 353 | (org-with-point-at chg 354 | (let ((org-trust-scanner-tags t)) 355 | (format "%s\n\t%s\n" 356 | (substring-no-properties 357 | (org-get-heading t t t t)) 358 | (org-web-track-current-changes nil "%p => %c" " | "))))) 359 | (org-web-track-update-files)))) 360 | (unless (string-blank-p mail-msg) 361 | ;; SMTP settings are required in advance (see smtpmail-xxx vaiables) 362 | (message-mail user-mail-address "Web Tracking Notification") 363 | (message-goto-body) 364 | (insert mail-msg) 365 | (message-send-and-exit)))) 366 | 367 | (require 'midnight) 368 | (add-hook 'midnight-hook #'exp/email-updated) 369 | (midnight-mode 1) 370 | 371 |  372 | File: org-web-track.info, Node: Q&A, Next: License, Prev: Extended Examples, Up: Top 373 | 374 | 5 Q&A 375 | ***** 376 | 377 | * Menu: 378 | 379 | * Network Certificate Issue:: 380 | 381 |  382 | File: org-web-track.info, Node: Network Certificate Issue, Up: Q&A 383 | 384 | 5.1 Network Certificate Issue 385 | ============================= 386 | 387 | Non-interactive invocation for ‘org-web-track-update-entry’ may fail due 388 | to an unverified network certificate. This issue can occur when 389 | accessing a website that offers an unverified certificate, and the 390 | variable ‘network-security-level’ is set to 'medium' or higher. To 391 | address the issue, accept the certificate by calling the 392 | ‘org-web-track-update-entry’ command interactively up-front. 393 | 394 |  395 | File: org-web-track.info, Node: License, Next: Indices, Prev: Q&A, Up: Top 396 | 397 | 6 License 398 | ********* 399 | 400 | GPLv3 401 | 402 |  403 | File: org-web-track.info, Node: Indices, Prev: License, Up: Top 404 | 405 | 7 Indices 406 | ********* 407 | 408 | * Menu: 409 | 410 | * Function index:: 411 | * Variable index:: 412 | * Concept index:: 413 | 414 |  415 | File: org-web-track.info, Node: Function index, Next: Variable index, Up: Indices 416 | 417 | 7.1 Function index 418 | ================== 419 | 420 | [index] 421 | * Menu: 422 | 423 | * org-web-track-agenda-columns: Displaying Column View. 424 | (line 12) 425 | * org-web-track-agenda-update: Displaying Column View. 426 | (line 12) 427 | * org-web-track-columns: Displaying Column View. 428 | (line 6) 429 | * org-web-track-report: Reporting and Creating Graph. 430 | (line 10) 431 | * org-web-track-set-http-headers: Sending Additional HTTP Headers. 432 | (line 6) 433 | * org-web-track-set-unix-socket: Accessing Unix Domain Socket Server. 434 | (line 6) 435 | * org-web-track-setup-entry: Defining Tracking Items. 436 | (line 35) 437 | * org-web-track-update-entry: Updating Values. (line 6) 438 | * org-web-track-update-files: Updating Values. (line 6) 439 | 440 |  441 | File: org-web-track.info, Node: Variable index, Next: Concept index, Prev: Function index, Up: Indices 442 | 443 | 7.2 Variable index 444 | ================== 445 | 446 | [index] 447 | * Menu: 448 | 449 | * org-web-track-content-fetcher-alist: Dealing with Dinamic Website. 450 | (line 6) 451 | * org-web-track-default-http-headers: Sending Additional HTTP Headers. 452 | (line 6) 453 | * org-web-track-files: Updating Values. (line 6) 454 | * org-web-track-selectors-alist: Defining Tracking Items. 455 | (line 6) 456 | * org-web-track-use-curl: Accessing Unix Domain Socket Server. 457 | (line 6) 458 | 459 |  460 | File: org-web-track.info, Node: Concept index, Prev: Variable index, Up: Indices 461 | 462 | 7.3 Concept index 463 | ================= 464 | 465 | [index] 466 | * Menu: 467 | 468 | * Installation instructions: Installation. (line 6) 469 | 470 | 471 |  472 | Tag Table: 473 | Node: Top234 474 | Node: Overview1194 475 | Node: Retrieving data1781 476 | Node: Installation2390 477 | Node: MELPA package2711 478 | Node: Basic Usage3215 479 | Node: Defining Tracking Items3564 480 | Node: Sending Additional HTTP Headers6210 481 | Node: Dealing with Dinamic Website7007 482 | Node: Accessing Unix Domain Socket Server7676 483 | Node: Updating Values8796 484 | Node: Displaying Column View9596 485 | Node: Reporting and Creating Graph10435 486 | Node: Extended Examples11166 487 | Node: Automatic Bulk Updating and Email Notifications11457 488 | Node: Q&A13217 489 | Node: Network Certificate Issue13362 490 | Node: License13899 491 | Node: Indices14009 492 | Node: Function index14166 493 | Node: Variable index15456 494 | Node: Concept index16281 495 |  496 | End Tag Table 497 | 498 |  499 | Local Variables: 500 | coding: utf-8 501 | End: 502 | -------------------------------------------------------------------------------- /org-web-track.texi: -------------------------------------------------------------------------------- 1 | \input texinfo @c -*- texinfo -*- 2 | @c %**start of header 3 | @setfilename org-web-track.info 4 | @settitle org-web-track.el - Web data tracking framework in Org Mode 5 | @documentencoding UTF-8 6 | @documentlanguage en 7 | @set MAINTAINERSITE @uref{https://github.com/p-snow/org-web-track,website} 8 | @set MAINTAINER p-snow 9 | @c %**end of header 10 | 11 | @dircategory Emacs 12 | @direntry 13 | * Org Web Track: (org-web-track). Web data tracking framework in Org Mode. 14 | @end direntry 15 | 16 | @finalout 17 | @titlepage 18 | @title org-web-track.el - Web data tracking framework in Org Mode 19 | @end titlepage 20 | 21 | @ifnottex 22 | @node Top 23 | @top org-web-track.el - Web data tracking framework in Org Mode 24 | 25 | @insertcopying 26 | 27 | Org Web Track provides an Org Mode framework that assists users in managing their values of interest on a website or via a Web API@. 28 | 29 | @end ifnottex 30 | 31 | @menu 32 | * Overview:: 33 | * Installation:: 34 | * Basic Usage:: 35 | * Extended Examples:: 36 | * Q&A:: 37 | * License:: 38 | * Indices:: 39 | 40 | @detailmenu 41 | --- The Detailed Node Listing --- 42 | 43 | Overview 44 | 45 | * Retrieving data:: 46 | 47 | Installation 48 | 49 | * MELPA package:: 50 | 51 | Basic Usage 52 | 53 | * Defining Tracking Items:: 54 | * Updating Values:: 55 | * Displaying Column View:: 56 | * Reporting and Creating Graph:: 57 | 58 | Defining Tracking Items 59 | 60 | * Sending Additional HTTP Headers:: 61 | * Dealing with Dinamic Website:: 62 | * Accessing Unix Domain Socket Server:: 63 | 64 | Extended Examples 65 | 66 | * Automatic Bulk Updating and Email Notifications:: 67 | 68 | Q&A 69 | 70 | * Network Certificate Issue:: 71 | 72 | Indices 73 | 74 | * Function index:: 75 | * Variable index:: 76 | * Concept index:: 77 | 78 | @end detailmenu 79 | @end menu 80 | 81 | @node Overview 82 | @chapter Overview 83 | 84 | Through the use of Org Web Track: 85 | @itemize 86 | @item 87 | Any location in the web page or any piece in the web API response can be an item to track 88 | @item 89 | Users can monitor changes for the item and manage them using the facilities of Org mode 90 | @item 91 | A set of items to track can be reviewed with their updated values in an Org column view 92 | @item 93 | Users can extract an Org table displaying value changes and create a visual graph using Gnuplot. 94 | @end itemize 95 | 96 | @menu 97 | * Retrieving data:: 98 | @end menu 99 | 100 | @node Retrieving data 101 | @section Retrieving data 102 | 103 | When users specify which snippet of data to track on web pages or web APIs, the following methods are available: 104 | 105 | @itemize 106 | @item 107 | CSS selectors, which are applied against the source code of the web page 108 | @item 109 | Elisp functions, which receive a DOM object or a JSON object from a web page or a web API and are expected to return a desired value from the argument 110 | @item 111 | Shell commands, which take a page source or an API response as STDIN and are expected to print a desired value to STDOUT 112 | @end itemize 113 | 114 | @node Installation 115 | @chapter Installation 116 | 117 | @cindex Installation instructions 118 | 119 | Requirements: 120 | @itemize 121 | @item 122 | Emacs 29.1 or higher 123 | @item 124 | @uref{https://github.com/tkf/emacs-request, request.el} v0.3.2 125 | @item 126 | @uref{https://github.com/zweifisch/enlive, enlive} v0.0.1 127 | @end itemize 128 | 129 | @menu 130 | * MELPA package:: 131 | @end menu 132 | 133 | @node MELPA package 134 | @section MELPA package 135 | 136 | Org Web Track can be installed from MELPA using package.el as follows: 137 | 138 | @enumerate 139 | @item 140 | Add melpa to package-archives 141 | @lisp 142 | (add-to-list 'package-archives 143 | '("melpa" . "https://melpa.org/packages/") 144 | t) 145 | @end lisp 146 | @item 147 | Refresh package contents 148 | @example 149 | M-x package-refresh-contents 150 | @end example 151 | @item 152 | Install Org Web Track 153 | @example 154 | M-x package-install 155 | @end example 156 | 157 | and select org-web-track 158 | @end enumerate 159 | 160 | @node Basic Usage 161 | @chapter Basic Usage 162 | 163 | In this section, the basic Org Web Track mechanism and fundamental command usage are described. 164 | 165 | @menu 166 | * Defining Tracking Items:: 167 | * Updating Values:: 168 | * Displaying Column View:: 169 | * Reporting and Creating Graph:: 170 | @end menu 171 | 172 | @node Defining Tracking Items 173 | @section Defining Tracking Items 174 | 175 | @vindex org-web-track-selectors-alist 176 | Before setting up each tracking item, users need to define @code{org-web-track-selectors-alist}, whose element consists of two components: URL-MATCH and SELECTOR@. Each element is responsible for selecting a value for the specific URL that matches URL-MATCH, a regexp. The SELECTOR will then be applied to the content of the HTTP response at the URL to extract the resulting value. 177 | 178 | A single URL-MATCH is associated with one or more SELECTORS@. Therefore, the element of the variable appears as either (URL-MATCH . SELECTOR) or (URL-MATCH SELECTORS@dots{}). Below is a typical example of how to set the variable: 179 | 180 | (setq org-web-track-selectors-alist '((``example\\.com/product'' . [.final-price]))) 181 | 182 | This code define how to extract product prices at the site ``example.com''. In the site, the price posits in the tag whose class is ``final-price''. This case, SELECTOR is CSS selector, one of available formats. SELECTOR can be more than that. Please refer to the documentation of @code{org-web-track-selectors-alist} for more detail. 183 | 184 | This code dictates how to extract product prices from the site ``example.com''. On the site, the price is located within a tag whose class is ``final-price''. In this case, SELECTOR is a vector, which signifies a CSS selector. Besides this, SELECTOR can also be a function or a string. This means it can represent an Elisp procedure or a shell command respectively. For more details, please refer to the documentation of @code{org-web-track-selectors-alist}. 185 | 186 | @findex org-web-track-setup-entry 187 | After appropriately defining @code{org-web-track-selectors-alist}, users can set up each specific tracking item by calling @code{org-web-track-setup-entry} on the desired org entry or before the first heading to create a new one in the org buffer. Users will be prompted to input the tracking URL, and then the updated value will be retrieved, stored, and displayed in the echo area according to the aforementioned settings. 188 | 189 | @example 190 | * Book ABC 191 | :PROPERTIES: 192 | :TRACK_URL: https://example.com/products/book-abc.html 193 | :TRACK_CURRENT_VALUE: $30 194 | :TRACK_LAST_UPDATED_TIME: [2024-07-18 Thu 16:57] 195 | :END: 196 | :LOGBOOK: 197 | - Update "$30" [2024-07-18 Thu 16:57] 198 | :END: 199 | @end example 200 | 201 | Some practical tracking item examples for specific real services are showcased on the Wiki page of the project website at @uref{https://github.com/p-snow/org-web-track/wiki}. 202 | 203 | @menu 204 | * Sending Additional HTTP Headers:: 205 | * Dealing with Dinamic Website:: 206 | * Accessing Unix Domain Socket Server:: 207 | @end menu 208 | 209 | @node Sending Additional HTTP Headers 210 | @subsection Sending Additional HTTP Headers 211 | 212 | @vindex org-web-track-default-http-headers 213 | @findex org-web-track-set-http-headers 214 | In an HTTP request message, a client can include a set of information known as an HTTP header, each element presented in a key-value pair format. This allows the client to send metadata to the server for various purposes, such as authentication or user identification. 215 | 216 | In Org Web Track, users can specify HTTP headers in a couple of ways. First, they can set a variable @code{org-web-track-default-http-headers} that is applied to every HTTP request. Second, they can execute a command @code{org-web-track-set-http-headers} that sets specific HTTP headers for individual entries. 217 | 218 | @node Dealing with Dinamic Website 219 | @subsection Dealing with Dinamic Website 220 | 221 | @vindex org-web-track-content-fetcher-alist 222 | The HTTP request backend of org-web-track, either cURL or url-retrieve, lacks the ability to read a dynamic website like a JS-rendered page. To work around this issue, org-web-track employs a delegation mechanism for fetching content. CONTENT-FETCHER in the org-web-track-content-fetcher-alist is used for this purpose. Users are free to implement any procedure using libraries such as Selenium or WebDriver in it. 223 | 224 | @node Accessing Unix Domain Socket Server 225 | @subsection Accessing Unix Domain Socket Server 226 | 227 | @findex org-web-track-set-unix-socket 228 | @vindex org-web-track-use-curl 229 | While org-web-track primarily focuses on the WWW server as the access target, users also have the option to connect to a Unix Domain Socket server, which provides HTTP services mainly on a local machine. A simple example of a Unix Socket server implementation complying with the org-web-track framework can be found at @uref{https://github.com/p-snow/socket-http-server}. Using this feature, non-HTTP services, such as Unix shell commands, can be effectively utilized within the org-web-track framework. 230 | 231 | Users who want to access the Unix Domain Socket server must set the socket's path by calling @code{org-web-track-set-unix-socket} at the desired tracking item. When this feature is active, the value of the variable @code{org-web-track-use-curl} will not be respected. The cURL program will implicitly be used as the fetching backend since url-retrieve cannot access the Unix Socket Server. 232 | 233 | @node Updating Values 234 | @section Updating Values 235 | 236 | @findex org-web-track-update-entry 237 | @findex org-web-track-update-files 238 | @vindex org-web-track-files 239 | The simplest way to update the value is to call @code{org-web-track-update-entry} on the desired org entry. If the retrieved value is updated compared to the last value, the updated value will be stored as the TRACK_CURRENT_VALUE org property; otherwise, the entry will remain unchanged. 240 | 241 | Alternatively, bulk updating is supported. To enable bulk updating, users must first define @code{org-web-track-files}. This variable should be a list of files in which all tracking items, identified by having the TRACK_URL property, are selected for bulk updating. To perform bulk updating, call @code{org-web-track-update-files}. 242 | 243 | @node Displaying Column View 244 | @section Displaying Column View 245 | 246 | @findex org-web-track-columns 247 | Column view in org-mode is a feature that displays properties in a table, providing a clear and comprehensive perspective. org-web-track offers a specialized column view where updated values are juxtaposed with their previous values for tracking items. To display the column view, call @code{org-web-track-columns} in org buffer. 248 | 249 | @findex org-web-track-agenda-columns 250 | @findex org-web-track-agenda-update 251 | If tracking items are scattered across many files, @code{org-web-track-agenda-columns} is useful as all tracking items in the aforementioned @code{org-web-track-files} are gathered in the agenda column view. Users can also update any item in the agenda column view by calling @code{org-web-track-agenda-update}. 252 | 253 | @node Reporting and Creating Graph 254 | @section Reporting and Creating Graph 255 | 256 | All updated values from the past are logged in the entry using the existing org log note feature. Log notes have a fixed format and are placed in a drawer only if @code{org-log-into-drawer} is non-nil. 257 | 258 | @findex org-web-track-report 259 | @code{org-web-track-report} creates an Org table where all log note values in the current Org entry are listed in ascending order of time, showing the transition of values over time. If called with C-u prefix, the command creates a visual graph using Gnuplot. Note that creating a graph requires the Gnuplot Emacs package and Gnuplot itself. 260 | 261 | @node Extended Examples 262 | @chapter Extended Examples 263 | 264 | In this section, examples of how to utilize @samp{org-web-track} extensively are showcased. 265 | 266 | @menu 267 | * Automatic Bulk Updating and Email Notifications:: 268 | @end menu 269 | 270 | @node Automatic Bulk Updating and Email Notifications 271 | @section Automatic Bulk Updating and Email Notifications 272 | 273 | While automatic updating may be ideal in certain situations, Org Web Track refrains from providing this feature directly to prevent potential data violations. However, users can enable automatic updating by calling @code{org-web-track-update-entry} or @code{org-web-track-update-files} from Elisp code. Below is an example implementation of automatic updates with email notifications scheduled for midnight. 274 | 275 | @lisp 276 | (defun exp/email-updated () 277 | "Check for updates on all tracking items in `org-web-track-files' 278 | and email me the updated list of items formatted as requested." 279 | (let* ((message-kill-buffer-on-exit t) 280 | (mail-msg (mapconcat 281 | (lambda (chg) 282 | (org-with-point-at chg 283 | (let ((org-trust-scanner-tags t)) 284 | (format "%s\n\t%s\n" 285 | (substring-no-properties 286 | (org-get-heading t t t t)) 287 | (org-web-track-current-changes nil "%p => %c" " | "))))) 288 | (org-web-track-update-files)))) 289 | (unless (string-blank-p mail-msg) 290 | ;; SMTP settings are required in advance (see smtpmail-xxx vaiables) 291 | (message-mail user-mail-address "Web Tracking Notification") 292 | (message-goto-body) 293 | (insert mail-msg) 294 | (message-send-and-exit)))) 295 | 296 | (require 'midnight) 297 | (add-hook 'midnight-hook #'exp/email-updated) 298 | (midnight-mode 1) 299 | @end lisp 300 | 301 | @node Q&A 302 | @chapter Q&A 303 | 304 | @menu 305 | * Network Certificate Issue:: 306 | @end menu 307 | 308 | @node Network Certificate Issue 309 | @section Network Certificate Issue 310 | 311 | Non-interactive invocation for @code{org-web-track-update-entry} may fail due to an unverified network certificate. This issue can occur when accessing a website that offers an unverified certificate, and the variable @code{network-security-level} is set to 'medium' or higher. To address the issue, accept the certificate by calling the @code{org-web-track-update-entry} command interactively up-front. 312 | 313 | @node License 314 | @chapter License 315 | 316 | GPLv3 317 | 318 | @node Indices 319 | @chapter Indices 320 | 321 | @menu 322 | * Function index:: 323 | * Variable index:: 324 | * Concept index:: 325 | @end menu 326 | 327 | @node Function index 328 | @section Function index 329 | 330 | @printindex fn 331 | 332 | @node Variable index 333 | @section Variable index 334 | 335 | @printindex vr 336 | 337 | @node Concept index 338 | @section Concept index 339 | 340 | @printindex cp 341 | 342 | @bye 343 | -------------------------------------------------------------------------------- /tests/track-entry.org: -------------------------------------------------------------------------------- 1 | #+TITLE: Track Entries 2 | 3 | * URL property variants 4 | :PROPERTIES: 5 | :CREATED: [2024-10-29 Tue 00:20] 6 | :END: 7 | ** A-001: No TRACK_URL 8 | ** A-002: Valid TRACK_URL 9 | :PROPERTIES: 10 | :TRACK_URL: https://www.example.com/product01 11 | :END: 12 | ** A-003: Valid TRACK_URL, which follows the org-link format 13 | :PROPERTIES: 14 | :TRACK_URL: [[https://www.example.com/product01][Example Com]] 15 | :END: 16 | ** A-004: Valid TRACK_URL and TRACK_UNIX_SOCKET 17 | :PROPERTIES: 18 | :TRACK_URL: https://www.example.com/product01 19 | :TRACK_UNIX_SOCKET: /tmp/test.sock 20 | :END: 21 | * URL property variants 22 | :PROPERTIES: 23 | :CREATED: [2024-10-29 Tue 00:12] 24 | :END: 25 | ** B-000: No URL 26 | :PROPERTIES: 27 | :TRACK_CURRENT_VALUE: $2 $20 28 | :TRACK_PREVIOUS_VALUE: $1 $10 29 | :END: 30 | ** B-001: Plain String 31 | :PROPERTIES: 32 | :TRACK_URL: https://www.example.com/product01 33 | :TRACK_CURRENT_VALUE: $2 $20 34 | :TRACK_PREVIOUS_VALUE: $1 $10 35 | :END: 36 | ** B-002: Org Link 37 | :PROPERTIES: 38 | :TRACK_URL: [[https://www.example.com/product01]] 39 | :TRACK_CURRENT_VALUE: $2 $20 40 | :TRACK_PREVIOUS_VALUE: $1 $10 41 | :END: 42 | ** B-003: Org Link with Description 43 | :PROPERTIES: 44 | :TRACK_URL: [[https://www.example.com/product01][shopping site]] 45 | :TRACK_CURRENT_VALUE: $2 $20 46 | :TRACK_PREVIOUS_VALUE: $1 $10 47 | :END: 48 | * Log variants 49 | :PROPERTIES: 50 | :CREATED: [2024-11-14 Thu 22:18] 51 | :END: 52 | 53 | ** L-000: 54 | :PROPERTIES: 55 | :CREATED: [2024-11-14 Thu 22:18] 56 | :END: 57 | :LOGBOOK: 58 | - Update "¥1,000 ¥100" [2024-11-12 Tue 06:30] 59 | - Update "¥2,000 ¥200" [2024-11-13 Wed 06:34] 60 | - Update "¥3,000 ¥300" [2024-11-14 Thu 06:31] 61 | :END: 62 | -------------------------------------------------------------------------------- /tests/unit-test--org-web-track.el: -------------------------------------------------------------------------------- 1 | ;;; unit-test--setup-entry.el --- Unit test for org-web-track -*- lexical-binding: t -*- 2 | 3 | ;; Author: p-snow 4 | ;; Homepage: https://github.com/p-snow/org-web-track 5 | 6 | ;; This file is not part of GNU Emacs 7 | 8 | ;; This program is free software: you can redistribute it and/or modify 9 | ;; it under the terms of the GNU General Public License as published by 10 | ;; the Free Software Foundation, either version 3 of the License, or 11 | ;; (at your option) any later version. 12 | 13 | ;; This program is distributed in the hope that it will be useful, 14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | ;; GNU General Public License for more details. 17 | 18 | ;; You should have received a copy of the GNU General Public License 19 | ;; along with this program. If not, see . 20 | 21 | ;;; Commentary: 22 | 23 | ;; 24 | 25 | ;;; Code: 26 | 27 | (require 'ert) 28 | (require 'org-web-track) 29 | (require 'project) 30 | 31 | (defvar test--org-web-track-selectors-alist 32 | '(("example.com" [.price]))) 33 | 34 | (ert-deftest test--setup-entry--invalid-url--noninteractive () 35 | "Test `org-web-track-setup-entry' with a URL that does not match any selector." 36 | (with-temp-buffer 37 | (org-mode) 38 | (insert-file-contents (expand-file-name "tests/track-entry.org" 39 | (project-root (project-current)))) 40 | (let ((url "https://dummy.com") 41 | (sock "/tmp/test.sock") 42 | (org-web-track-selectors-alist test--org-web-track-selectors-alist)) 43 | (goto-char (point-min)) 44 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 45 | (should-error (org-web-track-setup-entry url)))) 46 | (should (org-at-heading-p)) 47 | (should (string= (org-entry-get (point) org-web-track-url) 48 | url)) 49 | (re-search-forward "* A-001:") 50 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 51 | (should-error (org-web-track-setup-entry url)))) 52 | (should (string= (org-entry-get (point) org-web-track-url) 53 | url)) 54 | (re-search-forward "* A-002:") 55 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 56 | (should-error (org-web-track-setup-entry url)))) 57 | (should (string= (org-entry-get (point) org-web-track-url) 58 | url)) 59 | (re-search-forward "* A-003:") 60 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 61 | (should-error (org-web-track-setup-entry url)))) 62 | (should (string= (org-entry-get (point) org-web-track-url) 63 | url)) 64 | (re-search-forward "* A-004:") 65 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 66 | (should-error (org-web-track-setup-entry url))))))) 67 | 68 | (ert-deftest test--setup-entry--invalid-url--interactive () 69 | "Test `org-web-track-setup-entry' as an interactive command with a URL that does not match any selector." 70 | (with-temp-buffer 71 | (org-mode) 72 | (insert-file-contents (expand-file-name "tests/track-entry.org" 73 | (project-root (project-current)))) 74 | (let ((url "https://dummy.com") 75 | (sock "/tmp/test.sock") 76 | (org-web-track-selectors-alist test--org-web-track-selectors-alist) 77 | (executing-kbd-macro t)) 78 | (goto-char (point-min)) 79 | (let ((unread-command-events (listify-key-sequence 80 | (kbd (format "%s RET" url))))) 81 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 82 | (should-error (call-interactively #'org-web-track-setup-entry)))) 83 | (should (org-at-heading-p)) 84 | (should (string= (org-entry-get (point) org-web-track-url) 85 | url))) 86 | (let ((unread-command-events (listify-key-sequence 87 | (kbd (format "%s RET" url))))) 88 | (re-search-forward "* A-001:") 89 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 90 | (should-error (call-interactively #'org-web-track-setup-entry)))) 91 | (should (string= (org-entry-get (point) org-web-track-url) 92 | url))) 93 | (let ((unread-command-events (listify-key-sequence 94 | (kbd (format "y %s %s RET" 95 | (if noninteractive "RET" "") 96 | url))))) 97 | (re-search-forward "* A-002:") 98 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 99 | (should-error (call-interactively #'org-web-track-setup-entry)))) 100 | (should (string= (org-entry-get (point) org-web-track-url) 101 | url))) 102 | (let ((unread-command-events (listify-key-sequence 103 | (kbd (format "y %s %s RET" 104 | (if noninteractive "RET" "") 105 | url))))) 106 | (re-search-forward "* A-003:") 107 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 108 | (should-error (call-interactively #'org-web-track-setup-entry)))) 109 | (should (string= (org-entry-get (point) org-web-track-url) 110 | url))) 111 | (let ((unread-command-events (listify-key-sequence 112 | (kbd (format "y %s %s RET" 113 | (if noninteractive "RET" "") 114 | url))))) 115 | (re-search-forward "* A-004:") 116 | (should (equal `(user-error ,(format "No selector found responsible for %s in org-web-track-selectors-alist" url)) 117 | (should-error (call-interactively #'org-web-track-setup-entry)))) 118 | (should (string= (org-entry-get (point) org-web-track-url) 119 | url)) 120 | (should (string= (org-entry-get (point) org-web-track-unix-socket) 121 | sock)))))) 122 | 123 | (provide 'test-org-web-track) 124 | ;;; unit-test--setup-entry.el ends here 125 | -------------------------------------------------------------------------------- /tests/unit-test--report.el: -------------------------------------------------------------------------------- 1 | ;;; unit-test--report.el --- Unit test for org-web-track -*- lexical-binding: t -*- 2 | 3 | ;; Author: p-snow 4 | ;; Package-Requires: ((mocker "0.5.0")) 5 | ;; Homepage: https://github.com/p-snow/org-web-track 6 | 7 | ;; This file is not part of GNU Emacs 8 | 9 | ;; This program is free software: you can redistribute it and/or modify 10 | ;; it under the terms of the GNU General Public License as published by 11 | ;; the Free Software Foundation, either version 3 of the License, or 12 | ;; (at your option) any later version. 13 | 14 | ;; This program is distributed in the hope that it will be useful, 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;; GNU General Public License for more details. 18 | 19 | ;; You should have received a copy of the GNU General Public License 20 | ;; along with this program. If not, see . 21 | 22 | ;;; Commentary: 23 | 24 | ;; 25 | 26 | ;;; Code: 27 | 28 | (require 'ert) 29 | (require 'mocker) 30 | (require 'org-web-track) 31 | (require 'project) 32 | 33 | (ert-deftest test--report--no-plot () 34 | "Test `org-web-track-report' non plotting scenario." 35 | (with-temp-buffer 36 | (org-mode) 37 | (insert-file-contents (expand-file-name "tests/track-entry.org" 38 | (project-root (project-current)))) 39 | 40 | (re-search-forward "* L-000:") 41 | (org-next-visible-heading 1) 42 | (org-open-line 1) 43 | (org-web-track-report) 44 | (let ((answer (concat "| DATE | VALUE 1 | VALUE 2 |\n" 45 | "|------------+---------+---------|\n" 46 | "| 2024-11-12 | ¥1,000 | ¥100 |\n" 47 | "| 2024-11-13 | ¥2,000 | ¥200 |\n" 48 | "| 2024-11-14 | ¥3,000 | ¥300 |\n"))) 49 | (should (string-equal (buffer-substring-no-properties (point) (org-table-end)) 50 | answer))))) 51 | 52 | (ert-deftest test--report--plot () 53 | "Test `org-web-track-report' plotting scenario." 54 | (with-temp-buffer 55 | (org-mode) 56 | (insert-file-contents (expand-file-name "tests/track-entry.org" 57 | (project-root (project-current)))) 58 | 59 | (re-search-forward "* L-000:") 60 | (org-next-visible-heading 1) 61 | (org-open-line 1) 62 | (org-web-track-report '(4)) 63 | (let ((answer (concat "#+PLOT: ind:1 deps:(2 3) with:boxes type:2d\n" 64 | "#+PLOT: set:\"xdata time\"\n" 65 | "#+PLOT: set:\"timefmt '%Y-%m-%d'\"\n" 66 | "#+PLOT: set:\"xrange ['2024-11-11':'2024-11-15']\"\n" 67 | "| DATE | VALUE 1 | VALUE 2 |\n" 68 | "|------------+---------+---------|\n" 69 | "| 2024-11-12 | 1000 | 100 |\n" 70 | "| 2024-11-13 | 2000 | 200 |\n" 71 | "| 2024-11-14 | 3000 | 300 |\n"))) 72 | (should (string-equal (buffer-substring-no-properties (point) 73 | (save-excursion 74 | (re-search-forward "|") 75 | (org-table-end))) 76 | answer))))) 77 | 78 | (ert-deftest test--report--no-plot--custom-date-formate () 79 | "Test `org-web-track-report' non plotting scenario." 80 | (with-temp-buffer 81 | (org-mode) 82 | (insert-file-contents (expand-file-name "tests/track-entry.org" 83 | (project-root (project-current)))) 84 | 85 | (let ((org-web-track-report-date-format "%Y-%m-%d %H:%M") 86 | (answer (concat "| DATE | VALUE 1 | VALUE 2 |\n" 87 | "|------------------+---------+---------|\n" 88 | "| 2024-11-12 06:30 | ¥1,000 | ¥100 |\n" 89 | "| 2024-11-13 06:34 | ¥2,000 | ¥200 |\n" 90 | "| 2024-11-14 06:31 | ¥3,000 | ¥300 |\n"))) 91 | (re-search-forward "* L-000:") 92 | (org-next-visible-heading 1) 93 | (org-open-line 1) 94 | (org-web-track-report) 95 | (should (string-equal (buffer-substring-no-properties (point) (org-table-end)) 96 | answer))))) 97 | 98 | (ert-deftest test--report--plot--custom-date-format () 99 | "Test `org-web-track-report' plotting scenario." 100 | (with-temp-buffer 101 | (org-mode) 102 | (insert-file-contents (expand-file-name "tests/track-entry.org" 103 | (project-root (project-current)))) 104 | 105 | (let ((org-web-track-report-date-format "%Y-%m-%d %H:%M") 106 | (answer (concat "#+PLOT: ind:1 deps:(2 3) with:boxes type:2d\n" 107 | "#+PLOT: set:\"xdata time\"\n" 108 | "#+PLOT: set:\"timefmt '%Y-%m-%d %H:%M'\"\n" 109 | "#+PLOT: set:\"xrange ['2024-11-11':'2024-11-15']\"\n" 110 | "| DATE | VALUE 1 | VALUE 2 |\n" 111 | "|------------------+---------+---------|\n" 112 | "| 2024-11-12 06:30 | 1000 | 100 |\n" 113 | "| 2024-11-13 06:34 | 2000 | 200 |\n" 114 | "| 2024-11-14 06:31 | 3000 | 300 |\n"))) 115 | (re-search-forward "* L-000:") 116 | (org-next-visible-heading 1) 117 | (org-open-line 1) 118 | (org-web-track-report '(4)) 119 | (should (string-equal (buffer-substring-no-properties (point) 120 | (save-excursion 121 | (re-search-forward "|") 122 | (org-table-end))) 123 | answer))))) 124 | 125 | ;;; unit-test--report.el ends here 126 | -------------------------------------------------------------------------------- /tests/unit-test--update-entry.el: -------------------------------------------------------------------------------- 1 | ;;; unit-test--update-entry.el --- Unit test for org-web-track -*- lexical-binding: t -*- 2 | 3 | ;; Author: p-snow 4 | ;; Package-Requires: ((mocker "0.5.0")) 5 | ;; Homepage: https://github.com/p-snow/org-web-track 6 | 7 | ;; This file is not part of GNU Emacs 8 | 9 | ;; This program is free software: you can redistribute it and/or modify 10 | ;; it under the terms of the GNU General Public License as published by 11 | ;; the Free Software Foundation, either version 3 of the License, or 12 | ;; (at your option) any later version. 13 | 14 | ;; This program is distributed in the hope that it will be useful, 15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | ;; GNU General Public License for more details. 18 | 19 | ;; You should have received a copy of the GNU General Public License 20 | ;; along with this program. If not, see . 21 | 22 | ;;; Commentary: 23 | 24 | ;; 25 | 26 | ;;; Code: 27 | 28 | (require 'ert) 29 | (require 'mocker) 30 | (require 'org-web-track) 31 | (require 'project) 32 | 33 | (defvar test--org-web-track-selectors-alist 34 | '(("example.com" [.price]))) 35 | 36 | (ert-deftest test--update-entry--track-url () 37 | "Test `org-web-track-update-entry' with various URL patterns." 38 | (with-temp-buffer 39 | (org-mode) 40 | (insert-file-contents (expand-file-name "tests/track-entry.org" 41 | (project-root (project-current)))) 42 | 43 | (let* ((org-web-track-selectors-alist test--org-web-track-selectors-alist) 44 | (current-time-sans-sec (decode-time (current-time)))) 45 | (setf (nth 0 current-time-sans-sec) 0) 46 | 47 | (mocker-let ((org-web-track-retrieve-values (url sel x y) 48 | ((:input '("https://www.example.com/product01" ([\.price]) nil nil) :output '("$3" "$30"))))) 49 | ;; test B-000 50 | (re-search-forward "* B-000:") 51 | (should-error (org-web-track-update-entry)) 52 | (should (equal (org-entry-get-multivalued-property nil org-web-track-value) 53 | '("$2" "$20"))) 54 | (should (equal (org-entry-get-multivalued-property nil org-web-track-prev-value) 55 | '("$1" "$10"))) 56 | ;; test B-001 57 | (re-search-forward "* B-001:") 58 | (org-web-track-update-entry) 59 | (should (equal (org-entry-get-multivalued-property nil org-web-track-value) 60 | '("$3" "$30"))) 61 | (should (equal (org-entry-get-multivalued-property nil org-web-track-prev-value) 62 | '("$2" "$20"))) 63 | (should (time-equal-p current-time-sans-sec 64 | (org-parse-time-string (org-entry-get nil org-web-track-updated)))) 65 | ;; test B-002 66 | (re-search-forward "* B-002:") 67 | (org-web-track-update-entry) 68 | (should (equal (org-entry-get-multivalued-property nil org-web-track-value) 69 | '("$3" "$30"))) 70 | (should (equal (org-entry-get-multivalued-property nil org-web-track-prev-value) 71 | '("$2" "$20"))) 72 | (should (time-equal-p current-time-sans-sec 73 | (org-parse-time-string (org-entry-get nil org-web-track-updated)))) 74 | ;; test B-003 75 | (re-search-forward "* B-003:") 76 | (org-web-track-update-entry) 77 | (should (equal (org-entry-get-multivalued-property nil org-web-track-value) 78 | '("$3" "$30"))) 79 | (should (equal (org-entry-get-multivalued-property nil org-web-track-prev-value) 80 | '("$2" "$20"))) 81 | (should (time-equal-p current-time-sans-sec 82 | (org-parse-time-string (org-entry-get nil org-web-track-updated)))) 83 | ) 84 | ))) 85 | 86 | (provide 'test-org-web-track) 87 | ;;; unit-test--update-entry.el ends here 88 | --------------------------------------------------------------------------------