├── .gitignore ├── GPL.txt ├── README.md ├── pygmynote.pot ├── pygmynote.py ├── pygmynote.svg ├── pygmynote3.py └── sniptopygmynote.py /.gitignore: -------------------------------------------------------------------------------- 1 | .directory -------------------------------------------------------------------------------- /GPL.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Pygmynote 2 | 3 | Pygmynote is a command-line tool for storing and managing heterogeneous bit of data like notes, tasks, links, file attachments, etc. Pygmynote is written in Python and uses an SQLite database as its back end. 4 | 5 | ##Features 6 | 7 | - Add, update, archive, and delete records 8 | - Specify dates for records to turn them into tasks 9 | - Add long notes using an external text editor 10 | - Add records with attachments 11 | - Search records by note and by tag 12 | - View active and archived records 13 | - Run user-defined SQL queries 14 | - Pin and unpin records 15 | - Export records in the TSV format (tab-separated) 16 | - Backup the database 17 | - Generate an HTML file with records containing a specified tag 18 | 19 | ##Dependencies 20 | 21 | - Python 2.x or 3.x 22 | - nano or any other text editor 23 | 24 | ##Installation 25 | 26 | Clone the repository using the `git clone https://github.com/dmpop/pygmynote.git` command. Alternatively, download the provided *zip* or *tar* archive. By default, Pygmynote is configured to use the nano text editor, but you can change that by changing the *EDITOR* variable in the script. To specify a different backup directory, edit the *BACKUP* variable. 27 | 28 | ##Usage 29 | 30 | Open terminal, switch to the *pygmynote* directory and run the _pygmynote.py_ script in the terminal. Type *help* and press `Enter` to list the available commands. 31 | 32 | ##Localization 33 | 34 | cd pygmynote 35 | xgettext --language=Python --keyword=_ --output=pygmynote.pot pygmynote.py 36 | mkdir -p locale/xx/LC_MESSAGES 37 | cp pygmynote.pot locale/xx/LC_MESSAGES/pygmynote.po 38 | cd locale/xx/LC_MESSAGES 39 | msgfmt pygmynote.po -o pygmynote.mo 40 | 41 | $ LANGUAGE=xx python pygmynote.py 42 | 43 | ##License 44 | 45 | This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. 46 | 47 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 48 | 49 | You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,MA 02110-1301, USA. 50 | 51 | _Copyleft 2010-2016 Dmitri Popov_ 52 | 53 | Source code: [https://github.com/dmpop/pygmynote](https://github.com/dmpop/pygmynote) 54 | -------------------------------------------------------------------------------- /pygmynote.pot: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2014-01-30 17:34+0100\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=CHARSET\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | 20 | #: pygmynote.py:77 21 | msgid "Connection to the SQLite database failed!" 22 | msgstr "" 23 | 24 | #: pygmynote.py:83 25 | msgid "" 26 | "\n" 27 | " ( 0)>\n" 28 | " (( *))\n" 29 | " ||\n" 30 | "===========\"==\"=============\n" 31 | "Pygmynote is ready. Pile up!\n" 32 | "============================" 33 | msgstr "" 34 | 35 | #: pygmynote.py:91 36 | msgid "" 37 | "\n" 38 | "Type \"h\" and press ENTER" 39 | msgstr "" 40 | 41 | #: pygmynote.py:112 42 | msgid "" 43 | "\n" 44 | "-------------------------------------\n" 45 | "Pinned records and today's deadlines:\n" 46 | "-------------------------------------" 47 | msgstr "" 48 | 49 | #: pygmynote.py:132 50 | msgid "" 51 | "\n" 52 | "===================\n" 53 | "Pygmynote commands:\n" 54 | "===================\n" 55 | "\n" 56 | "i\tInsert a new record\n" 57 | "l\tInsert a new long record\n" 58 | "f\tInsert a new record with an attachment\n" 59 | "s\tSave an attachment\n" 60 | "u\tUpdate a record\n" 61 | "p\tPin a record\n" 62 | "x\tUnpin a record\n" 63 | "n\tSearch records by note\n" 64 | "t\tSearch records by tag\n" 65 | "a\tShow active records\n" 66 | "ar\tShow archived records\n" 67 | "tl\tShow tasks\n" 68 | "at\tShow records with attachments\n" 69 | "e\tExport records as CSV file\n" 70 | "g\tGenerate HTML page with records containing a certain tag\n" 71 | "d\tDelete a record by its ID\n" 72 | "b Backup the database\n" 73 | "q\tQuit" 74 | msgstr "" 75 | 76 | #: pygmynote.py:160 pygmynote.py:190 77 | msgid "Note: " 78 | msgstr "" 79 | 80 | #: pygmynote.py:161 pygmynote.py:191 pygmynote.py:285 81 | msgid "Tags: " 82 | msgstr "" 83 | 84 | #: pygmynote.py:162 pygmynote.py:180 85 | msgid "Due date (yyyy-mm-dd). Press ENTER to skip: " 86 | msgstr "" 87 | 88 | #: pygmynote.py:167 pygmynote.py:185 pygmynote.py:199 89 | msgid "" 90 | "\n" 91 | "Record has been added." 92 | msgstr "" 93 | 94 | #: pygmynote.py:192 95 | msgid "Enter path to file (e.g., /home/user/foo.png): " 96 | msgstr "" 97 | 98 | #: pygmynote.py:204 pygmynote.py:269 pygmynote.py:301 pygmynote.py:309 99 | msgid "Record id: " 100 | msgstr "" 101 | 102 | #: pygmynote.py:205 103 | msgid "Specify full path and file name (e.g., /home/user/foo.png): " 104 | msgstr "" 105 | 106 | #: pygmynote.py:213 107 | msgid "" 108 | "\n" 109 | "File has been saved." 110 | msgstr "" 111 | 112 | #: pygmynote.py:218 113 | msgid "Search notes for: " 114 | msgstr "" 115 | 116 | #: pygmynote.py:226 pygmynote.py:239 pygmynote.py:251 pygmynote.py:263 117 | #: pygmynote.py:325 pygmynote.py:337 118 | msgid "Record count: " 119 | msgstr "" 120 | 121 | #: pygmynote.py:232 122 | msgid "Search by tag: " 123 | msgstr "" 124 | 125 | #: pygmynote.py:270 126 | msgid "Update note [0], tags [1], due date [2], or archive [3]: " 127 | msgstr "" 128 | 129 | #: pygmynote.py:290 130 | msgid "Due date: " 131 | msgstr "" 132 | 133 | #: pygmynote.py:296 134 | msgid "" 135 | "\n" 136 | "Record has been updated." 137 | msgstr "" 138 | 139 | #: pygmynote.py:304 140 | msgid "" 141 | "\n" 142 | "Record has been pinned." 143 | msgstr "" 144 | 145 | #: pygmynote.py:312 146 | msgid "" 147 | "\n" 148 | "Record has been unpinned." 149 | msgstr "" 150 | 151 | #: pygmynote.py:345 152 | msgid "" 153 | "\n" 154 | "Record has been deleted." 155 | msgstr "" 156 | 157 | #: pygmynote.py:355 158 | msgid "" 159 | "\n" 160 | "Backup copy of the database has been been saved in " 161 | msgstr "" 162 | 163 | #: pygmynote.py:368 164 | msgid "" 165 | "\n" 166 | "Records have been saved in the " 167 | msgstr "" 168 | 169 | #: pygmynote.py:368 170 | msgid " file." 171 | msgstr "" 172 | 173 | #: pygmynote.py:373 174 | msgid "Tag: " 175 | msgstr "" 176 | 177 | #: pygmynote.py:385 178 | msgid " file has been generated." 179 | msgstr "" 180 | 181 | #: pygmynote.py:388 182 | msgid "" 183 | "\n" 184 | "\n" 185 | "Error: " 186 | msgstr "" 187 | 188 | #: pygmynote.py:388 189 | msgid " Please try again." 190 | msgstr "" 191 | 192 | #: pygmynote.py:392 193 | msgid "" 194 | "\n" 195 | " ( 0)>\n" 196 | " (( *))\n" 197 | " ||\n" 198 | "========\"==\"=========\n" 199 | "Bye! Have a nice day.\n" 200 | "=====================\n" 201 | msgstr "" 202 | -------------------------------------------------------------------------------- /pygmynote.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | Pygmynote is a command-line tool for storing and managing heterogeneous bit of data like notes, tasks, links, file attachments, etc. Pygmynote is written in Python and uses an SQLite database as its back end. 6 | 7 | Thanks to Luis Cabrera Sauco for implementing SQLite and i18 support. 8 | """ 9 | 10 | __author__ = 'Dmitri Popov [dmpop@linux.com]' 11 | __copyright__ = 'Copyleft 2011-2016 Dmitri Popov' 12 | __license__ = 'GPLv3' 13 | __version__ = '0.11.05' 14 | __URL__ = 'http://www.github.com/dmpop/pygmynote' 15 | 16 | import sys 17 | import datetime 18 | import os 19 | import time 20 | import calendar 21 | import gettext 22 | import tempfile 23 | import subprocess 24 | import shutil 25 | import codecs 26 | import webbrowser 27 | 28 | ### Settings ### 29 | 30 | EDITOR = 'nano' 31 | DB = 'pygmynote.sqlite' 32 | BACKUP = 'pygmynotebackup/' # Note the trailing slash 33 | EXPORT_FILE = 'pygmynote.tsv' 34 | HTML_FILE = 'pygmynote.html' 35 | 36 | ENC = 'UTF-8' 37 | DOMAIN = 'pygmynote' 38 | 39 | # Terminal colors 40 | 41 | class termcolor: 42 | GREEN = '\033[1;32m' 43 | BLUE = '\033[1;34m' 44 | GRAY = '\033[1;30m' 45 | YELLOW = '\033[1;33m' 46 | HIGHLIGHT = '\033[1;43m' 47 | RED = '\033[1;31m' 48 | END = '\033[1;m' 49 | 50 | def disable(self): 51 | self.GREEN = '' 52 | self.BLUE = '' 53 | self.GRAY = '' 54 | self.YELLOW = '' 55 | self.RED = '' 56 | self.END = '' 57 | 58 | try: 59 | TRANSLATION = gettext.translation(DOMAIN, './locale') 60 | _ = TRANSLATION.ugettext 61 | except IOError: 62 | _ = gettext.gettext 63 | 64 | try: 65 | import sqlite3 as sqlite 66 | except ImportError: 67 | from pysqlite2 import dbapi2 as sqlite 68 | 69 | if os.path.exists(DB): 70 | CREATE = False 71 | else: 72 | CREATE = True 73 | 74 | try: 75 | conn = sqlite.connect(DB) 76 | cursor = conn.cursor() 77 | except: 78 | sys.exit(_('Connection to the SQLite database failed!')) 79 | 80 | today = time.strftime('%Y-%m-%d') 81 | command = '' 82 | counter = 0 83 | 84 | print termcolor.GREEN + _(""" 85 | ( 0)> 86 | (( *)) 87 | || 88 | ==========="=="============= 89 | Pygmynote is ready. Pile up! 90 | ============================""") + termcolor.END 91 | 92 | print termcolor.BLUE + _("""\nType \"h\" and press ENTER""") + termcolor.END 93 | 94 | def smartquotes(selection): 95 | selection=selection.replace("'", "’") 96 | selection=selection.replace("\"", "”") 97 | return selection 98 | 99 | 100 | if CREATE == True: 101 | CREATE_SQL = \ 102 | "CREATE TABLE notes (\ 103 | id INTEGER PRIMARY KEY UNIQUE NOT NULL,\ 104 | note VARCHAR(1024),\ 105 | file BLOB,\ 106 | due DATE,\ 107 | type VARCHAR(1),\ 108 | ext VARCHAR(3),\ 109 | tags VARCHAR(256));" 110 | cursor.execute(CREATE_SQL) 111 | conn.commit() 112 | 113 | print _(""" 114 | ------------------------------------- 115 | Pinned records and today's deadlines: 116 | -------------------------------------""") 117 | 118 | cursor.execute ("SELECT id, note, tags FROM notes WHERE type = '3' ORDER BY id ASC") 119 | for row in cursor: 120 | print '\n' + termcolor.GREEN + str(row[0]) + termcolor.END + ' ' + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END 121 | 122 | cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due = '" + today + "' AND type <> '0' ORDER BY id ASC") 123 | for row in cursor: 124 | print '\n' + str(row[0]) + ' -- ' + termcolor.GREEN +str(row[1]) + ' ' + termcolor.END + unicode(row[2]) + termcolor.GRAY + ' [' + unicode(row[3]) + ']' + termcolor.END 125 | 126 | while command != 'q': 127 | 128 | try: 129 | 130 | command = raw_input('\n>') 131 | 132 | if command == 'h': 133 | print termcolor.GREEN + _(""" 134 | =================== 135 | Pygmynote commands: 136 | =================== 137 | 138 | i Insert a new record 139 | l Insert a new long record 140 | f Insert a new record with an attachment 141 | s Save an attachment 142 | u Update a record 143 | p Pin a record 144 | x Unpin a record 145 | n Search records by note 146 | t Search records by tag 147 | a Show active records 148 | ar Show archived records 149 | tl Show tasks 150 | at Show records with attachments 151 | sql Run a user-defined SQL query 152 | e Export records as CSV file 153 | g Generate HTML page with records containing a certain tag 154 | d Delete a record by its ID 155 | b Backup the database 156 | q Quit""") + termcolor.END 157 | 158 | elif command == 'i': 159 | 160 | # Insert a new record 161 | 162 | record_note = smartquotes(raw_input(_('Note: '))) 163 | record_tags = smartquotes(raw_input(_('Tags: '))) 164 | record_due = raw_input(_('Due date (yyyy-mm-dd). Press ENTER to skip: ')) 165 | record_type = "1" 166 | sql_query = "INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')" % (record_note, record_due, record_tags, record_type) 167 | cursor.execute(sql_query) 168 | conn.commit() 169 | cursor.execute("SELECT MAX(id) FROM notes") 170 | for row in cursor: 171 | max_id = str(row[0]) 172 | print termcolor.GREEN + _('\nRecord ') + max_id +_(' has been added.') + termcolor.END 173 | elif command == 'l': 174 | 175 | # Insert a new long record 176 | # http://stackoverflow.com/questions/3076798/start-nano-as-a-subprocess-from-python-capture-input 177 | 178 | f = tempfile.NamedTemporaryFile(mode='w+t', delete=False) 179 | n = f.name 180 | f.close() 181 | subprocess.call([EDITOR, n]) 182 | with open(n) as f: 183 | record_note = smartquotes(f.read()) 184 | record_tags = smartquotes(raw_input('Tags: ')) 185 | record_due = raw_input(_('Due date (yyyy-mm-dd). Press ENTER to skip: ')) 186 | record_type = "1" 187 | sql_query = "INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')" % (record_note, record_due, record_tags, record_type) 188 | cursor.execute(sql_query) 189 | conn.commit() 190 | cursor.execute("SELECT MAX(id) FROM notes") 191 | for row in cursor: 192 | max_id = str(row[0]) 193 | print termcolor.GREEN + _('\nRecord ') + max_id +_(' has been added.') + termcolor.END 194 | elif command == 'f': 195 | 196 | # Insert a new record with file 197 | 198 | record_note = smartquotes(raw_input(_('Note: '))) 199 | record_tags = smartquotes(raw_input(_('Tags: '))) 200 | record_file = smartquotes(raw_input(_('Enter path to file (e.g., /home/user/foo.png): '))) 201 | record_type="1" 202 | f=open(record_file.rstrip(), 'rb') 203 | ablob = f.read() 204 | f.close() 205 | cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + record_note + "', '" + record_tags + "', '" + record_type + "', '" + record_file[-3:] + "', ?)", [sqlite.Binary(ablob)]) 206 | conn.commit() 207 | cursor.execute("SELECT MAX(id) FROM notes") 208 | for row in cursor: 209 | max_id = str(row[0]) 210 | print termcolor.GREEN + _('\nRecord ') + max_id +_(' has been added.') + termcolor.END 211 | elif command == 's': 212 | 213 | # Save attachment 214 | 215 | record_id = raw_input(_('Record id: ')) 216 | output_file=raw_input(_('Specify full path and file name (e.g., /home/user/foo.png): ')) 217 | f=open(output_file, 'wb') 218 | cursor.execute ("SELECT file FROM notes WHERE id='" + record_id + "'") 219 | ablob = cursor.fetchone() 220 | f.write(ablob[0]) 221 | f.close() 222 | cursor.close() 223 | conn.commit() 224 | print termcolor.GREEN + _('\nFile has been saved.') + termcolor.END 225 | elif command == 'n': 226 | 227 | # Search records by note 228 | 229 | record_note = raw_input(_('Search notes for: ')) 230 | cursor.execute("SELECT id, note, tags FROM notes WHERE note LIKE '%" 231 | + record_note + "%'ORDER BY id ASC") 232 | print '\n-----' 233 | for row in cursor: 234 | print termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END 235 | counter = counter + 1 236 | print '\n-----' 237 | print termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter) 238 | counter = 0 239 | elif command == 't': 240 | 241 | # Search records by tag 242 | 243 | search_tag = raw_input (_('Search by tag: ')) 244 | cursor.execute("SELECT id, note, tags FROM notes WHERE tags LIKE '%" + search_tag + "%' AND type='1' ORDER BY id ASC") 245 | print '\n-----' 246 | for row in cursor: 247 | print termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END 248 | counter = counter + 1 249 | print '\n-----' 250 | print termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter) 251 | counter = 0 252 | elif command == 'a': 253 | 254 | # Show active records 255 | 256 | cursor.execute("SELECT id, note, tags FROM notes WHERE type='1' ORDER BY id ASC") 257 | print '\n-----' 258 | for row in cursor: 259 | print termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END 260 | counter = counter + 1 261 | print '\n-----' 262 | print termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter) 263 | counter = 0 264 | elif command == 'ar': 265 | 266 | # Show archived records 267 | 268 | cursor.execute("SELECT id, note, tags FROM notes WHERE type='0' ORDER BY id ASC") 269 | print '\n-----' 270 | for row in cursor: 271 | print termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END 272 | counter = counter + 1 273 | print '\n-----' 274 | print termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter) 275 | counter = 0 276 | elif command == 'sql': 277 | 278 | # Run a user-defined SQL query 279 | 280 | sql_query = raw_input ('SELECT id, note, due, tags FROM notes ') 281 | cursor.execute("SELECT id, note, due, tags FROM notes " + sql_query) 282 | print '\n-----' 283 | for row in cursor: 284 | print termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + str(row[2])+ ' [' + unicode(row[3]) + ']' + termcolor.END 285 | counter = counter + 1 286 | print '\n-----' 287 | print termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter) 288 | counter = 0 289 | elif command == 'u': 290 | 291 | # Update a record 292 | 293 | record_id = raw_input(_('Record id: ')) 294 | record_type = raw_input(_('Update note [0], tags [1], due date [2], or archive [3]: ')) 295 | if record_type == '0': 296 | cursor.execute ("SELECT id, note FROM notes WHERE id='" + record_id + "'") 297 | row = cursor.fetchone() 298 | f = tempfile.NamedTemporaryFile(mode='w+t', delete=False) 299 | n = f.name 300 | f.write(row[1].encode(ENC)) 301 | f.close() 302 | subprocess.call([EDITOR, n]) 303 | with open(n) as f: 304 | updated_note = smartquotes(f.read()) 305 | sanitized_sql = smartquotes(updated_note) 306 | cursor.execute("UPDATE notes SET note='" + sanitized_sql 307 | + "' WHERE id='" + record_id + "'") 308 | elif record_type == '1': 309 | updated_tags = raw_input(_('Tags: ')) 310 | sanitized_sql = smartquotes(updated_tags) 311 | cursor.execute("UPDATE notes SET tags='" + sanitized_sql 312 | + "' WHERE id='" + record_id + "'") 313 | elif record_type == '2': 314 | updated_due = raw_input(_('Due date: ')) 315 | cursor.execute("UPDATE notes SET due='" + updated_due 316 | + "' WHERE id='" + record_id + "'") 317 | else: 318 | cursor.execute("UPDATE notes SET type='0' WHERE id='" + record_id + "'") 319 | conn.commit() 320 | print termcolor.GREEN + _('\nRecord has been updated.') +termcolor.END 321 | elif command == 'p': 322 | 323 | # Pin a record 324 | 325 | record_id = raw_input(_('Record id: ')) 326 | cursor.execute("UPDATE notes SET type='3' WHERE id='" + record_id + "'") 327 | conn.commit() 328 | print termcolor.GREEN + _('\nRecord has been pinned.') +termcolor.END 329 | elif command == 'x': 330 | 331 | # Unpin a record 332 | 333 | record_id = raw_input(_('Record id: ')) 334 | cursor.execute("UPDATE notes SET type='1' WHERE id='" + record_id + "'") 335 | conn.commit() 336 | print termcolor.GREEN + _('\nRecord has been unpinned.') +termcolor.END 337 | elif command == 'tl': 338 | 339 | # Show tasks 340 | 341 | cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due <> '' AND tags NOT LIKE '%private%' AND type = '1' ORDER BY due ASC") 342 | print '\n-----' 343 | now = datetime.datetime.now() 344 | calendar.prmonth(now.year, now.month) 345 | for row in cursor: 346 | print '\n' + str(row[0]) + ' -- ' + termcolor.GREEN +str(row[1]) + ' ' + termcolor.END + unicode(row[2]) + termcolor.GRAY + ' [' + unicode(row[3]) + ']' + termcolor.END 347 | counter = counter + 1 348 | print '\n-----' 349 | print termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter) 350 | counter = 0 351 | elif command == 'at': 352 | 353 | # Show records with attachments 354 | 355 | cursor.execute("SELECT id, note, tags, ext FROM notes WHERE ext <> 'None' AND type='1' ORDER BY id ASC") 356 | print '\n-----' 357 | for row in cursor: 358 | print termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + '] ' + termcolor.END + termcolor.HIGHLIGHT + str(row[3]) + termcolor.END 359 | counter = counter + 1 360 | print '\n-----' 361 | print termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter) 362 | counter = 0 363 | elif command == 'd': 364 | 365 | # Delete a record by its ID 366 | 367 | record_id = raw_input('Delete note ID: ') 368 | cursor.execute("DELETE FROM notes WHERE ID='" + record_id + "'") 369 | print termcolor.GREEN + _('\nRecord has been deleted.') + termcolor.END 370 | conn.commit() 371 | elif command == 'b': 372 | 373 | # Backup the database 374 | 375 | if not os.path.exists(BACKUP): 376 | os.makedirs(BACKUP) 377 | shutil.copy('pygmynote.sqlite', BACKUP) 378 | os.rename(BACKUP + 'pygmynote.sqlite', BACKUP + today + '-pygmynote.sqlite') 379 | print termcolor.GREEN + _('\nBackup copy of the database has been been saved in ') + BACKUP + termcolor.END 380 | elif command == 'e': 381 | 382 | # Export records 383 | 384 | cursor.execute("SELECT id, note, tags, due FROM notes ORDER BY id ASC") 385 | if os.path.exists(EXPORT_FILE): 386 | os.remove(EXPORT_FILE) 387 | for row in cursor: 388 | f = EXPORT_FILE 389 | file = codecs.open(f, 'a', encoding=ENC) 390 | file.write('%s\t%s\t[%s]\t%s\n' % (row[0], row[1], row[2], row[3])) 391 | file.close() 392 | print termcolor.GREEN + _('\nRecords have been saved in the ') + EXPORT_FILE + _(' file.') + termcolor.END 393 | elif command == 'g': 394 | 395 | # Generate an HTML file 396 | 397 | search_tag = smartquotes(raw_input(_('Tag: '))) 398 | cursor.execute("SELECT note, tags FROM notes WHERE tags LIKE '%" + search_tag + "%' AND type='1' ORDER BY id ASC") 399 | if os.path.exists(HTML_FILE): 400 | os.remove(HTML_FILE) 401 | f = HTML_FILE 402 | file = codecs.open(f, 'a', encoding=ENC) 403 | file.write('\n\t\n\t\n\t\n\t\n\tPygmynote\n\t\n\t\n\n\t
\n\t

\n\t

Pygmynote

\n\n\t\n') 404 | for row in cursor: 405 | file.write('\t\n\t' % (row[0], row[1])) 406 | file.write('\n\t

%s

Tags: %s

\n\n\t
\n\t
\n\n\t\n') 407 | file.close() 408 | print ('\n') 409 | print termcolor.GREEN + HTML_FILE + _(' file has been generated.') + termcolor.END 410 | webbrowser.open(HTML_FILE) 411 | 412 | except: 413 | print _('\n\nError: ') + termcolor.RED + str(sys.exc_info()[0]) + termcolor.END + _(' Please try again.') 414 | 415 | continue 416 | 417 | print termcolor.YELLOW + _(""" 418 | ( 0)> 419 | (( *)) 420 | || 421 | ========"=="========= 422 | Bye! Have a nice day. 423 | =====================\n""") + termcolor.END 424 | 425 | cursor.close() 426 | conn.close() 427 | -------------------------------------------------------------------------------- /pygmynote.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 23 | 48 | 50 | 51 | 53 | image/svg+xml 54 | 56 | 57 | 58 | 59 | 60 | 65 | 68 | 70 | pygmynote 82 | 83 | 86 | 93 | 100 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /pygmynote3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | Pygmynote is a command-line tool for storing and managing heterogeneous bit of data like notes, tasks, links, file attachments, etc. Pygmynote is written in Python and uses an SQLite database as its back end. 6 | 7 | Thanks to Luis Cabrera Sauco for implementing SQLite and i18 support. 8 | """ 9 | 10 | __author__ = "Dmitri Popov [dmpop@linux.com]" 11 | __copyright__ = "Copyleft 2011-2016 Dmitri Popov" 12 | __license__ = "GPLv3" 13 | __version__ = "0.11.05" 14 | __URL__ = "http://www.github.com/dmpop/pygmynote" 15 | 16 | import sys 17 | import datetime 18 | import os 19 | import time 20 | import calendar 21 | import gettext 22 | import sqlite3 as sqlite 23 | import tempfile 24 | import subprocess 25 | import shutil 26 | import codecs 27 | import webbrowser 28 | 29 | ### Settings ### 30 | 31 | EDITOR = 'nano' 32 | DB = 'pygmynote.sqlite' 33 | BACKUP = 'pygmynotebackup/' # Note the trailing slash 34 | EXPORT_FILE = 'pygmynote.tsv' 35 | HTML_FILE = 'pygmynote.html' 36 | HTML_FILE_TITLE = 'Pygmynote' 37 | 38 | ENC = "UTF-8" 39 | DOMAIN = "pygmynote" 40 | 41 | # Terminal colors 42 | 43 | class termcolor: 44 | GREEN = '\033[1;32m' 45 | BLUE = '\033[1;34m' 46 | GRAY = '\033[1;30m' 47 | YELLOW = '\033[1;33m' 48 | RED = '\033[1;31m' 49 | END = '\033[1;m' 50 | 51 | def disable(self): 52 | self.GREEN = '' 53 | self.BLUE = '' 54 | self.GRAY = '' 55 | self.YELLOW = '' 56 | self.RED = '' 57 | self.END = '' 58 | 59 | try: 60 | TRANSLATION = gettext.translation(DOMAIN, "./locale") 61 | _ = TRANSLATION.ugettext 62 | except IOError: 63 | _ = gettext.gettext 64 | 65 | 66 | if os.path.exists(DB): 67 | CREATE = False 68 | else: 69 | CREATE = True 70 | 71 | try: 72 | conn = sqlite.connect(DB) 73 | cursor = conn.cursor() 74 | except: 75 | sys.exit(_("Connection to the SQLite database failed!")) 76 | 77 | today = time.strftime("%Y-%m-%d") 78 | command = "" 79 | counter = 0 80 | 81 | print (termcolor.GREEN + _(""" 82 | ( 0) 83 | (( *)) 84 | || 85 | ==========="=="============= 86 | Pygmynote is ready. Pile up! 87 | ============================""") + termcolor.END) 88 | 89 | print (termcolor.BLUE + _("""\nType \"h\" and press ENTER""") + termcolor.END) 90 | 91 | def smartquotes(selection): 92 | selection=selection.replace("'", "’") 93 | selection=selection.replace("\"", "”") 94 | return selection 95 | 96 | 97 | if CREATE == True: 98 | CREATE_SQL = \ 99 | "CREATE TABLE notes (\ 100 | id INTEGER PRIMARY KEY UNIQUE NOT NULL,\ 101 | note VARCHAR(1024),\ 102 | file BLOB,\ 103 | due DATE,\ 104 | type VARCHAR(3),\ 105 | ext VARCHAR(3),\ 106 | tags VARCHAR(256));" 107 | cursor.execute(CREATE_SQL) 108 | conn.commit() 109 | 110 | print (_(""" 111 | ------------------------------------- 112 | Pinned records and today's deadlines: 113 | -------------------------------------""")) 114 | 115 | cursor.execute ("SELECT id, note, tags FROM notes WHERE type = '3' ORDER BY id ASC") 116 | for row in cursor: 117 | print ('\n' + termcolor.GREEN + str(row[0]) + termcolor.END + ' ' + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END) 118 | 119 | cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due = '" + today + "' AND type <> '0' ORDER BY id ASC") 120 | for row in cursor: 121 | print ('\n' + str(row[0]) + ' -- ' + termcolor.GREEN +str(row[1]) + ' ' + termcolor.END + unicode(row[2]) + termcolor.GRAY + ' [' + unicode(row[3]) + ']' + termcolor.END) 122 | 123 | while command != "q": 124 | 125 | try: 126 | 127 | command = input('\n>') 128 | 129 | if command == 'h': 130 | print (termcolor.GREEN + _(""" 131 | =================== 132 | Pygmynote commands: 133 | =================== 134 | 135 | i Insert a new record 136 | l Insert a new long record 137 | f Insert a new record with an attachment 138 | s Save an attachment 139 | u Update a record 140 | p Pin a record 141 | x Unpin a record 142 | n Search records by note 143 | t Search records by tag 144 | a Show active records 145 | ar Show archived records 146 | tl Show tasks 147 | at Show records with attachments 148 | sql Run a user-defined SQL query 149 | e Export records as CSV file 150 | g Generate HTML page with records containing a certain tag 151 | d Delete a record by its ID 152 | b Backup the database 153 | q Quit""") + termcolor.END) 154 | 155 | elif command == "i": 156 | 157 | # Insert a new record 158 | 159 | record_note = smartquotes(input(_('Note: '))) 160 | record_tags = smartquotes(input(_('Tags: '))) 161 | record_due = input(_('Due date (yyyy-mm-dd). Press ENTER to skip: ')) 162 | record_type = '1' 163 | sql_query = "INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')" % (record_note, record_due, record_tags, record_type) 164 | cursor.execute(sql_query) 165 | conn.commit() 166 | cursor.execute("SELECT MAX(id) FROM notes") 167 | for row in cursor: 168 | max_id = str(row[0]) 169 | print (termcolor.GREEN + _('\nRecord ') + max_id +_(' has been added.') + termcolor.END) 170 | elif command == 'l': 171 | 172 | # Insert a new long record 173 | # http://stackoverflow.com/questions/3076798/start-nano-as-a-subprocess-from-python-capture-input 174 | 175 | f = tempfile.NamedTemporaryFile(mode='w+t', delete=False) 176 | n = f.name 177 | f.close() 178 | subprocess.call([EDITOR, n]) 179 | with open(n) as f: 180 | record_note = smartquotes(f.read()) 181 | record_tags = smartquotes(input('Tags: ')) 182 | record_due = input(_('Due date (yyyy-mm-dd). Press Enter to skip: ')) 183 | record_type = '1' 184 | sql_query = "INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')" % (record_note, record_due, record_tags, record_type) 185 | cursor.execute(sql_query) 186 | conn.commit() 187 | cursor.execute("SELECT MAX(id) FROM notes") 188 | for row in cursor: 189 | max_id = str(row[0]) 190 | print (termcolor.GREEN + _('\nRecord ') + max_id +_(' has been added.') + termcolor.END) 191 | elif command == 'f': 192 | 193 | # Insert a new record with file 194 | 195 | record_note = smartquotes(input(_('Note: '))) 196 | record_tags = smartquotes(input(_('Tags: '))) 197 | rfile = smartquotes(input(_('Enter path to file (e.g., /home/user/foo.png): '))) 198 | record_type='1' 199 | f=open(rfile.rstrip(), 'rb') 200 | ablob = f.read() 201 | f.close() 202 | cursor.execute("INSERT INTO notes (note, tags, type, ext, file) VALUES('" + record_note + "', '" + record_tags + "', '" + record_type + "', '" + rfile[-3:] + "', ?)", [sqlite.Binary(ablob)]) 203 | conn.commit() 204 | cursor.execute("SELECT MAX(id) FROM notes") 205 | for row in cursor: 206 | max_id = str(row[0]) 207 | print (termcolor.GREEN + _('\nRecord ') + max_id +_(' has been added.') + termcolor.END) 208 | elif command == 's': 209 | 210 | # Save file 211 | 212 | record_id = input(_('Record id: ')) 213 | output_file=input(_('Specify full path and file name (e.g., /home/user/foo.png): ')) 214 | f=open(output_file, 'wb') 215 | cursor.execute ("SELECT file FROM notes WHERE id='" + record_id + "'") 216 | ablob = cursor.fetchone() 217 | f.write(ablob[0]) 218 | f.close() 219 | cursor.close() 220 | conn.commit() 221 | print (termcolor.GREEN + _('\nFile has been saved.') +termcolor.END) 222 | elif command == 'n': 223 | 224 | # Search records by note 225 | 226 | record_note = input(_('Search notes for: ')) 227 | cursor.execute("SELECT id, note, tags FROM notes WHERE note LIKE '%" 228 | + record_note + "%'ORDER BY id ASC") 229 | print ("\n-----") 230 | for row in cursor: 231 | print (termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END) 232 | counter = counter + 1 233 | print ("\n-----") 234 | print (termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter)) 235 | counter = 0 236 | elif command == 't': 237 | 238 | # Search records by tag 239 | 240 | search_tag = input (_('Search by tag: ')) 241 | cursor.execute("SELECT id, note, tags FROM notes WHERE tags LIKE '%" + search_tag + "%' AND type='1' ORDER BY id ASC") 242 | print ('\n-----') 243 | for row in cursor: 244 | print (termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END) 245 | counter = counter + 1 246 | print ('\n-----') 247 | print (termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter)) 248 | counter = 0 249 | elif command == 'a': 250 | 251 | # Show active records 252 | 253 | cursor.execute("SELECT id, note, tags FROM notes WHERE type='1' ORDER BY id ASC") 254 | print ("\n-----") 255 | for row in cursor: 256 | print (termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END) 257 | counter = counter + 1 258 | print ('\n-----') 259 | print (termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter)) 260 | counter = 0 261 | elif command == 'ar': 262 | 263 | # Show archived records 264 | 265 | cursor.execute("SELECT id, note, tags FROM notes WHERE type='0' ORDER BY id ASC") 266 | print ('\n-----') 267 | for row in cursor: 268 | print (termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + ']' + termcolor.END) 269 | counter = counter + 1 270 | print ('\n-----') 271 | print (termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter)) 272 | counter = 0 273 | elif command == 'sql': 274 | 275 | # Run a user-defined SQL query 276 | 277 | sql_query = raw_input ('SELECT id, note, due, tags FROM notes ') 278 | cursor.execute("SELECT id, note, due, tags FROM notes " + sql_query) 279 | print ('\n-----') 280 | for row in cursor: 281 | print (termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + str(row[2])+ ' [' + unicode(row[3]) + ']' + termcolor.END) 282 | counter = counter + 1 283 | print '\n-----' 284 | print (termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter)) 285 | counter = 0 286 | elif command == 'u': 287 | 288 | # Update a record 289 | 290 | record_id = input(_('Record id: ')) 291 | record_type = input(_('Update note [0], tags [1], due date [2], or archive [3]: ')) 292 | if record_type == '0': 293 | cursor.execute ("SELECT id, note FROM notes WHERE id='" + record_id + "'") 294 | row = cursor.fetchone() 295 | f = tempfile.NamedTemporaryFile(mode='w+t', delete=False) 296 | n = f.name 297 | f.write(row[1].encode(ENC)) 298 | f.close() 299 | subprocess.call([EDITOR, n]) 300 | with open(n) as f: 301 | updated_note = smartquotes(f.read()) 302 | sanitized_sql = smartquotes(updated_note) 303 | cursor.execute("UPDATE notes SET note='" + sanitized_sql 304 | + "' WHERE id='" + record_id + "'") 305 | elif record_type == '1': 306 | updated_tags = input(_('Tags: ')) 307 | sanitized_sql = smartquotes(updated_tags) 308 | cursor.execute("UPDATE notes SET tags='" + sanitized_sql 309 | + "' WHERE id='" + record_id + "'") 310 | elif record_type == '2': 311 | updated_due = input(_('Due date: ')) 312 | cursor.execute("UPDATE notes SET due='" + updated_due 313 | + "' WHERE id='" + record_id + "'") 314 | else: 315 | record_type = '0' 316 | cursor.execute("UPDATE notes SET type='" + record_type 317 | + "' WHERE id='" + record_id + "'") 318 | conn.commit() 319 | print (termcolor.GREEN + _('\nRecord has been updated.') + termcolor.END) 320 | elif command == 'p': 321 | 322 | # Pin a record 323 | 324 | record_id = raw_input(_('Record id: ')) 325 | cursor.execute("UPDATE notes SET type='3' WHERE id='" + record_id + "'") 326 | conn.commit() 327 | print termcolor.GREEN + _('\nRecord has been pinned.') +termcolor.END 328 | elif command == 'x': 329 | 330 | # Unpin a record 331 | 332 | record_id = raw_input(_('Record id: ')) 333 | cursor.execute("UPDATE notes SET type='1' WHERE id='" + record_id + "'") 334 | conn.commit() 335 | print termcolor.GREEN + _('\nRecord has been unpinned.') +termcolor.END 336 | elif command == 'tl': 337 | 338 | # Show tasks 339 | 340 | cursor.execute ("SELECT due, id, note, tags FROM notes WHERE due <> '' AND tags NOT LIKE '%private%' AND type = '1' ORDER BY due ASC") 341 | print ("\n-----") 342 | now = datetime.datetime.now() 343 | calendar.prmonth(now.year, now.month) 344 | for row in cursor: 345 | print ('\n' + str(row[0]) + ' -- ' + termcolor.GREEN +str(row[1]) + ' ' + termcolor.END + unicode(row[2]) + termcolor.GRAY + ' [' + unicode(row[3]) + ']' + termcolor.END) 346 | counter = counter + 1 347 | print ('\n-----') 348 | print (termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter)) 349 | counter = 0 350 | elif command == 'at': 351 | 352 | # Show records with attachments 353 | 354 | cursor.execute("SELECT id, note, tags, ext FROM notes WHERE ext <> 'None' AND type='1' ORDER BY id ASC") 355 | print ('\n-----') 356 | for row in cursor: 357 | print (termcolor.GREEN + '\n' +str(row[0]) + ' ' + termcolor.END + unicode(row[1]) + termcolor.GRAY + ' [' + unicode(row[2]) + '] ' + termcolor.END + termcolor.HIGHLIGHT + str(row[3]) + termcolor.END) 358 | counter = counter + 1 359 | print ('\n-----') 360 | print (termcolor.BLUE + _('Record count: ') + termcolor.END + str(counter)) 361 | counter = 0 362 | elif command == 'd': 363 | 364 | # Delete a record by its ID 365 | 366 | record_id = input(_('Delete note ID: ')) 367 | cursor.execute("DELETE FROM notes WHERE ID='" + record_id + "'") 368 | print (termcolor.GREEN + _('\nRecord has been deleted.') + termcolor.END) 369 | conn.commit() 370 | elif command == 'b': 371 | 372 | # Backup the database 373 | 374 | if not os.path.exists(BACKUP): 375 | os.makedirs(BACKUP) 376 | shutil.copy('pygmynote.sqlite', BACKUP) 377 | os.rename(BACKUP + 'pygmynote.sqlite', BACKUP + today + '-pygmynote.sqlite') 378 | print (termcolor.GREEN + _('\nBackup copy of the database has been been saved in ') + BACKUP + termcolor.END) 379 | elif command == 'e': 380 | 381 | # Export records 382 | 383 | cursor.execute("SELECT id, note, tags, due FROM notes ORDER BY id ASC") 384 | if os.path.exists(EXPORT_FILE): 385 | os.remove(EXPORT_FILE) 386 | for row in cursor: 387 | f = EXPORT_FILE 388 | file = codecs.open(f, 'a', encoding=ENC) 389 | file.write('%s\t%s\t[%s]\t%s\n' % (row[0], row[1], row[2], row[3])) 390 | file.close() 391 | print (termcolor.GREEN + _('\nRecords have been saved in the ') + EXPORT_FILE + _(' file.') + termcolor.END) 392 | elif command == 'g': 393 | 394 | # Generate an HTML file 395 | 396 | search_tag = smartquotes(raw_input(_('Tag: '))) 397 | cursor.execute("SELECT note, tags FROM notes WHERE tags LIKE '%" + search_tag + "%' AND type='1' ORDER BY id ASC") 398 | if os.path.exists(HTML_FILE): 399 | os.remove(HTML_FILE) 400 | f = HTML_FILE 401 | file = codecs.open(f, 'a', encoding=ENC) 402 | file.write('\n\t\n\t\n\t\n\t\n\t'+ HTML_FILE_TITLE + '\n\t\n\t\n\n\t
\n\t

\n\t

Pygmynote

\n\n\t\n') 403 | for row in cursor: 404 | file.write('\t\n\t' % (row[0], row[1])) 405 | file.write('\n\t

%s

Tags: %s

\n\n\t
\n\t
\n\n\t\n') 406 | file.close() 407 | print ('\n') 408 | print (termcolor.GREEN + HTML_FILE + _(' file has been generated.') + termcolor.END) 409 | webbrowser.open(HTML_FILE) 410 | 411 | except: 412 | print (_('\n\nError: ') + termcolor.RED + str(sys.exc_info()[0]) + termcolor.END + _(' Please try again.')) 413 | 414 | continue 415 | 416 | print (termcolor.YELLOW + _(""" 417 | ( 0)> 418 | (( *)) 419 | || 420 | ========"=="========= 421 | Bye! Have a nice day. 422 | =====================\n""") + termcolor.END) 423 | 424 | cursor.close() 425 | conn.close() 426 | -------------------------------------------------------------------------------- /sniptopygmynote.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import pygtk, gtk, wx 3 | import sqlite3 as sqlite 4 | pygtk.require('2.0') 5 | 6 | DB = 'pygmynote.sqlite' 7 | 8 | conn = sqlite.connect(DB) 9 | cursor = conn.cursor() 10 | 11 | def escapechar(sel): 12 | sel=sel.replace("\'", "\''") 13 | sel=sel.replace("\"", "\"""") 14 | return sel 15 | 16 | clipboard = gtk.clipboard_get() 17 | snip = clipboard.wait_for_text() 18 | 19 | app = wx.PySimpleApp() 20 | tags = wx.TextEntryDialog(None, "Tags:","Add Tags", "", style=wx.OK|wx.CANCEL) 21 | if tags.ShowModal() == wx.ID_OK: 22 | notetags = tags.GetValue() 23 | tags.Destroy() 24 | 25 | notetext = escapechar(snip) 26 | notedue = "" 27 | notetype = "1" 28 | sqlquery = \ 29 | "INSERT INTO notes (note, due, tags, type) VALUES ('%s', '%s', '%s', '%s')"\ 30 | % (notetext, notedue, notetags, notetype) 31 | cursor.execute(sqlquery) 32 | conn.commit() 33 | 34 | message = wx.MessageDialog(None, "Snip saved. All done!", "Done", wx.OK) 35 | message.ShowModal() 36 | message.Destroy() 37 | --------------------------------------------------------------------------------