├── .gitignore ├── LICENSE.md ├── README.md ├── centr.png ├── config_template.py ├── db.py ├── feeditem.py ├── install_and_run.bat ├── install_and_run.sh ├── keepass.py ├── main.py ├── migrations ├── README ├── alembic.ini ├── env.py ├── script.py.mako └── versions │ ├── 8a3e1e2_initial_model.py │ └── e2300a5_new_link_item.py ├── modules ├── __init__.py ├── m_github.py ├── m_reddit.py ├── m_rss.py ├── m_runtastic.py └── m_soundcloud.py ├── requirements.txt ├── static ├── images │ ├── centr_fav.png │ ├── centr_logo.png │ ├── github.png │ ├── icon_open.png │ ├── reddit.png │ ├── rss.png │ ├── runtastic.png │ └── soundcloud.png ├── js │ ├── main.js │ └── waveform.js └── styles │ ├── github.css │ ├── layout.css │ ├── reddit.css │ ├── rss.css │ └── soundcloud.css └── templates ├── cards ├── github.html ├── reddit.html ├── rss.html ├── runtastic.html └── soundcloud.html ├── dashboard.html ├── footer.html └── header.html /.gitignore: -------------------------------------------------------------------------------- 1 | config.py 2 | known_sessions_file 3 | *.pyc 4 | *.db 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The GNU General Public License, Version 3, 29 June 2007 (GPLv3) 2 | =============================================================== 3 | 4 | > Copyright © 2007 5 | > Free Software Foundation, Inc. 6 | > <> 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this license 9 | document, but changing it is not allowed. 10 | 11 | 12 | Preamble 13 | -------- 14 | 15 | The GNU General Public License is a free, copyleft license for software and 16 | other kinds of works. 17 | 18 | The licenses for most software and other practical works are designed to take 19 | away your freedom to share and change the works. By contrast, the GNU General 20 | Public License is intended to guarantee your freedom to share and change all 21 | versions of a program--to make sure it remains free software for all its users. 22 | We, the Free Software Foundation, use the GNU General Public License for most of 23 | our software; it applies also to any other work released this way by its 24 | authors. You can apply it to your programs, too. 25 | 26 | When we speak of free software, we are referring to freedom, not price. Our 27 | General Public Licenses are designed to make sure that you have the freedom to 28 | distribute copies of free software (and charge for them if you wish), that you 29 | receive source code or can get it if you want it, that you can change the 30 | software or use pieces of it in new free programs, and that you know you can do 31 | these things. 32 | 33 | To protect your rights, we need to prevent others from denying you these rights 34 | or asking you to surrender the rights. Therefore, you have certain 35 | responsibilities if you distribute copies of the software, or if you modify it: 36 | responsibilities to respect the freedom of others. 37 | 38 | For example, if you distribute copies of such a program, whether gratis or for a 39 | fee, you must pass on to the recipients the same freedoms that you received. You 40 | must make sure that they, too, receive or can get the source code. And you must 41 | show them these terms so they know their rights. 42 | 43 | Developers that use the GNU GPL protect your rights with two steps: (1) assert 44 | copyright on the software, and (2) offer you this License giving you legal 45 | permission to copy, distribute and/or modify it. 46 | 47 | For the developers' and authors' protection, the GPL clearly explains that there 48 | is no warranty for this free software. For both users' and authors' sake, the 49 | GPL requires that modified versions be marked as changed, so that their problems 50 | will not be attributed erroneously to authors of previous versions. 51 | 52 | Some devices are designed to deny users access to install or run modified 53 | versions of the software inside them, although the manufacturer can do so. This 54 | is fundamentally incompatible with the aim of protecting users' freedom to 55 | change the software. The systematic pattern of such abuse occurs in the area of 56 | products for individuals to use, which is precisely where it is most 57 | unacceptable. Therefore, we have designed this version of the GPL to prohibit 58 | the practice for those products. If such problems arise substantially in other 59 | domains, we stand ready to extend this provision to those domains in future 60 | versions of the GPL, as needed to protect the freedom of users. 61 | 62 | Finally, every program is threatened constantly by software patents. States 63 | should not allow patents to restrict development and use of software on 64 | general-purpose computers, but in those that do, we wish to avoid the special 65 | danger that patents applied to a free program could make it effectively 66 | proprietary. To prevent this, the GPL assures that patents cannot be used to 67 | render the program non-free. 68 | 69 | The precise terms and conditions for copying, distribution and modification 70 | follow. 71 | 72 | 73 | TERMS AND CONDITIONS 74 | -------------------- 75 | 76 | 77 | ### 0. Definitions. 78 | 79 | "This License refers to version 3 of the GNU General Public License. 80 | 81 | "Copyright" also means copyright-like laws that apply to other kinds of works, 82 | such as semiconductor masks. 83 | 84 | "The Program" refers to any copyrightable work licensed under this License. Each 85 | licensee is addressed as "you". "Licensees" and "recipients" may be individuals 86 | or organizations. 87 | 88 | To "modify" a work means to copy from or adapt all or part of the work in a 89 | fashion requiring copyright permission, other than the making of an exact copy. 90 | The resulting work is called a "modified version" of the earlier work or a work 91 | "based on" the earlier work. 92 | 93 | A "covered work" means either the unmodified Program or a work based on the 94 | Program. 95 | 96 | To "propagate" a work means to do anything with it that, without permission, 97 | would make you directly or secondarily liable for infringement under applicable 98 | copyright law, except executing it on a computer or modifying a private copy. 99 | Propagation includes copying, distribution (with or without modification), 100 | making available to the public, and in some countries other activities as well. 101 | 102 | To "convey" a work means any kind of propagation that enables other parties to 103 | make or receive copies. Mere interaction with a user through a computer network, 104 | with no transfer of a copy, is not conveying. 105 | 106 | An interactive user interface displays "Appropriate Legal Notices" to the extent 107 | that it includes a convenient and prominently visible feature that (1) displays 108 | an appropriate copyright notice, and (2) tells the user that there is no 109 | warranty for the work (except to the extent that warranties are provided), that 110 | licensees may convey the work under this License, and how to view a copy of this 111 | License. If the interface presents a list of user commands or options, such as a 112 | menu, a prominent item in the list meets this criterion. 113 | 114 | 115 | ### 1. Source Code. 116 | 117 | The "source code" for a work means the preferred form of the work for making 118 | modifications to it. "Object code" means any non-source form of a work. 119 | 120 | A "Standard Interface" means an interface that either is an official standard 121 | defined by a recognized standards body, or, in the case of interfaces specified 122 | for a particular programming language, one that is widely used among developers 123 | working in that language. 124 | 125 | The "System Libraries" of an executable work include anything, other than the 126 | work as a whole, that (a) is included in the normal form of packaging a Major 127 | Component, but which is not part of that Major Component, and (b) serves only to 128 | enable use of the work with that Major Component, or to implement a Standard 129 | Interface for which an implementation is available to the public in source code 130 | form. A "Major Component", in this context, means a major essential component 131 | (kernel, window system, and so on) of the specific operating system (if any) on 132 | which the executable work runs, or a compiler used to produce the work, or an 133 | object code interpreter used to run it. 134 | 135 | The "Corresponding Source" for a work in object code form means all the source 136 | code needed to generate, install, and (for an executable work) run the object 137 | code and to modify the work, including scripts to control those activities. 138 | However, it does not include the work's System Libraries, or general-purpose 139 | tools or generally available free programs which are used unmodified in 140 | performing those activities but which are not part of the work. For example, 141 | Corresponding Source includes interface definition files associated with source 142 | files for the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, such as by 144 | intimate data communication or control flow between those subprograms and other 145 | parts of the work. 146 | 147 | The Corresponding Source need not include anything that users can regenerate 148 | automatically from other parts of the Corresponding Source. 149 | 150 | The Corresponding Source for a work in source code form is that same work. 151 | 152 | 153 | ### 2. Basic Permissions. 154 | 155 | All rights granted under this License are granted for the term of copyright on 156 | the Program, and are irrevocable provided the stated conditions are met. This 157 | License explicitly affirms your unlimited permission to run the unmodified 158 | Program. The output from running a covered work is covered by this License only 159 | if the output, given its content, constitutes a covered work. This License 160 | acknowledges your rights of fair use or other equivalent, as provided by 161 | copyright law. 162 | 163 | You may make, run and propagate covered works that you do not convey, without 164 | conditions so long as your license otherwise remains in force. You may convey 165 | covered works to others for the sole purpose of having them make modifications 166 | exclusively for you, or provide you with facilities for running those works, 167 | provided that you comply with the terms of this License in conveying all 168 | material for which you do not control copyright. Those thus making or running 169 | the covered works for you must do so exclusively on your behalf, under your 170 | direction and control, on terms that prohibit them from making any copies of 171 | your copyrighted material outside their relationship with you. 172 | 173 | Conveying under any other circumstances is permitted solely under the conditions 174 | stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 175 | 176 | 177 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 178 | 179 | No covered work shall be deemed part of an effective technological measure under 180 | any applicable law fulfilling obligations under article 11 of the WIPO copyright 181 | treaty adopted on 20 December 1996, or similar laws prohibiting or restricting 182 | circumvention of such measures. 183 | 184 | When you convey a covered work, you waive any legal power to forbid 185 | circumvention of technological measures to the extent such circumvention is 186 | effected by exercising rights under this License with respect to the covered 187 | work, and you disclaim any intention to limit operation or modification of the 188 | work as a means of enforcing, against the work's users, your or third parties' 189 | legal rights to forbid circumvention of technological measures. 190 | 191 | 192 | ### 4. Conveying Verbatim Copies. 193 | 194 | You may convey verbatim copies of the Program's source code as you receive it, 195 | in any medium, provided that you conspicuously and appropriately publish on each 196 | copy an appropriate copyright notice; keep intact all notices stating that this 197 | License and any non-permissive terms added in accord with section 7 apply to the 198 | code; keep intact all notices of the absence of any warranty; and give all 199 | recipients a copy of this License along with the Program. 200 | 201 | You may charge any price or no price for each copy that you convey, and you may 202 | offer support or warranty protection for a fee. 203 | 204 | 205 | ### 5. Conveying Modified Source Versions. 206 | 207 | You may convey a work based on the Program, or the modifications to produce it 208 | from the Program, in the form of source code under the terms of section 4, 209 | provided that you also meet all of these conditions: 210 | 211 | * **a)** The work must carry prominent notices stating that you modified it, 212 | and giving a relevant date. 213 | 214 | * **b)** The work must carry prominent notices stating that it is released 215 | under this License and any conditions added under section 7. This 216 | requirement modifies the requirement in section 4 to "keep intact all 217 | notices". 218 | 219 | * **c)** You must license the entire work, as a whole, under this License to 220 | anyone who comes into possession of a copy. This License will therefore 221 | apply, along with any applicable section 7 additional terms, to the whole of 222 | the work, and all its parts, regardless of how they are packaged. This 223 | License gives no permission to license the work in any other way, but it 224 | does not invalidate such permission if you have separately received it. 225 | 226 | * **d)** If the work has interactive user interfaces, each must display 227 | Appropriate Legal Notices; however, if the Program has interactive 228 | interfaces that do not display Appropriate Legal Notices, your work need not 229 | make them do so. 230 | 231 | A compilation of a covered work with other separate and independent works, 232 | which are not by their nature extensions of the covered work, and which are 233 | not combined with it such as to form a larger program, in or on a volume of 234 | a storage or distribution medium, is called an "aggregate" if the 235 | compilation and its resulting copyright are not used to limit the access or 236 | legal rights of the compilation's users beyond what the individual works 237 | permit. Inclusion of a covered work in an aggregate does not cause this 238 | License to apply to the other parts of the aggregate. 239 | 240 | 241 | ### 6. Conveying Non-Source Forms. 242 | 243 | You may convey a covered work in object code form under the terms of sections 4 244 | and 5, provided that you also convey the machine-readable Corresponding Source 245 | under the terms of this License, in one of these ways: 246 | 247 | * **a)** Convey the object code in, or embodied in, a physical product 248 | (including a physical distribution medium), accompanied by the Corresponding 249 | Source fixed on a durable physical medium customarily used for software 250 | interchange. 251 | 252 | * **b)** Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by a written offer, 254 | valid for at least three years and valid for as long as you offer spare 255 | parts or customer support for that product model, to give anyone who 256 | possesses the object code either (1) a copy of the Corresponding Source for 257 | all the software in the product that is covered by this License, on a 258 | durable physical medium customarily used for software interchange, for a 259 | price no more than your reasonable cost of physically performing this 260 | conveying of source, or (2) access to copy the Corresponding Source from a 261 | network server at no charge. 262 | 263 | * **c)** Convey individual copies of the object code with a copy of the 264 | written offer to provide the Corresponding Source. This alternative is 265 | allowed only occasionally and noncommercially, and only if you received the 266 | object code with such an offer, in accord with subsection 6b. 267 | 268 | * **d)** Convey the object code by offering access from a designated place 269 | (gratis or for a charge), and offer equivalent access to the Corresponding 270 | Source in the same way through the same place at no further charge. You need 271 | not require recipients to copy the Corresponding Source along with the 272 | object code. If the place to copy the object code is a network server, the 273 | Corresponding Source may be on a different server (operated by you or a 274 | third party) that supports equivalent copying facilities, provided you 275 | maintain clear directions next to the object code saying where to find the 276 | Corresponding Source. Regardless of what server hosts the Corresponding 277 | Source, you remain obligated to ensure that it is available for as long as 278 | needed to satisfy these requirements. 279 | 280 | * **e)** Convey the object code using peer-to-peer transmission, provided you 281 | inform other peers where the object code and Corresponding Source of the 282 | work are being offered to the general public at no charge under subsection 283 | 6d. 284 | 285 | A separable portion of the object code, whose source code is excluded from 286 | the Corresponding Source as a System Library, need not be included in 287 | conveying the object code work. 288 | 289 | A "User Product" is either (1) a "consumer product", which means any 290 | tangible personal property which is normally used for personal, family, or 291 | household purposes, or (2) anything designed or sold for incorporation into 292 | a dwelling. In determining whether a product is a consumer product, doubtful 293 | cases shall be resolved in favor of coverage. For a particular product 294 | received by a particular user, "normally used" refers to a typical or common 295 | use of that class of product, regardless of the status of the particular 296 | user or of the way in which the particular user actually uses, or expects or 297 | is expected to use, the product. A product is a consumer product regardless 298 | of whether the product has substantial commercial, industrial or non- 299 | consumer uses, unless such uses represent the only significant mode of use 300 | of the product. 301 | 302 | "Installation Information" for a User Product means any methods, procedures, 303 | authorization keys, or other information required to install and execute 304 | modified versions of a covered work in that User Product from a modified 305 | version of its Corresponding Source. The information must suffice to ensure 306 | that the continued functioning of the modified object code is in no case 307 | prevented or interfered with solely because modification has been made. 308 | 309 | If you convey an object code work under this section in, or with, or 310 | specifically for use in, a User Product, and the conveying occurs as part of 311 | a transaction in which the right of possession and use of the User Product 312 | is transferred to the recipient in perpetuity or for a fixed term 313 | (regardless of how the transaction is characterized), the Corresponding 314 | Source conveyed under this section must be accompanied by the Installation 315 | Information. But this requirement does not apply if neither you nor any 316 | third party retains the ability to install modified object code on the User 317 | Product (for example, the work has been installed in ROM). 318 | 319 | The requirement to provide Installation Information does not include a 320 | requirement to continue to provide support service, warranty, or updates for 321 | a work that has been modified or installed by the recipient, or for the User 322 | Product in which it has been modified or installed. Access to a network may 323 | be denied when the modification itself materially and adversely affects the 324 | operation of the network or violates the rules and protocols for 325 | communication across the network. 326 | 327 | Corresponding Source conveyed, and Installation Information provided, in 328 | accord with this section must be in a format that is publicly documented 329 | (and with an implementation available to the public in source code form), 330 | and must require no special password or key for unpacking, reading or 331 | copying. 332 | 333 | 334 | ### 7. Additional Terms. 335 | 336 | "Additional permissions" are terms that supplement the terms of this License by 337 | making exceptions from one or more of its conditions. Additional permissions 338 | that are applicable to the entire Program shall be treated as though they were 339 | included in this License, to the extent that they are valid under applicable 340 | law. If additional permissions apply only to part of the Program, that part may 341 | be used separately under those permissions, but the entire Program remains 342 | governed by this License without regard to the additional permissions. 343 | 344 | When you convey a copy of a covered work, you may at your option remove any 345 | additional permissions from that copy, or from any part of it. (Additional 346 | permissions may be written to require their own removal in certain cases when 347 | you modify the work.) You may place additional permissions on material, added by 348 | you to a covered work, for which you have or can give appropriate copyright 349 | permission. 350 | 351 | Notwithstanding any other provision of this License, for material you add to a 352 | covered work, you may (if authorized by the copyright holders of that material) 353 | supplement the terms of this License with terms: 354 | 355 | * **a)** Disclaiming warranty or limiting liability differently from the terms 356 | of sections 15 and 16 of this License; or 357 | 358 | * **b)** Requiring preservation of specified reasonable legal notices or 359 | author attributions in that material or in the Appropriate Legal Notices 360 | displayed by works containing it; or 361 | 362 | * **c)** Prohibiting misrepresentation of the origin of that material, or 363 | requiring that modified versions of such material be marked in reasonable 364 | ways as different from the original version; or 365 | 366 | * **d)** Limiting the use for publicity purposes of names of licensors or 367 | authors of the material; or 368 | 369 | * **e)** Declining to grant rights under trademark law for use of some trade 370 | names, trademarks, or service marks; or 371 | 372 | * **f)** Requiring indemnification of licensors and authors of that material 373 | by anyone who conveys the material (or modified versions of it) with 374 | contractual assumptions of liability to the recipient, for any liability 375 | that these contractual assumptions directly impose on those licensors and 376 | authors. 377 | 378 | All other non-permissive additional terms are considered "further restrictions" 379 | within the meaning of section 10. If the Program as you received it, or any part 380 | of it, contains a notice stating that it is governed by this License along with 381 | a term that is a further restriction, you may remove that term. If a license 382 | document contains a further restriction but permits relicensing or conveying 383 | under this License, you may add to a covered work material governed by the terms 384 | of that license document, provided that the further restriction does not survive 385 | such relicensing or conveying. 386 | 387 | If you add terms to a covered work in accord with this section, you must place, 388 | in the relevant source files, a statement of the additional terms that apply to 389 | those files, or a notice indicating where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the form of a 392 | separately written license, or stated as exceptions; the above requirements 393 | apply either way. 394 | 395 | 396 | ### 8. Termination. 397 | 398 | You may not propagate or modify a covered work except as expressly provided 399 | under this License. Any attempt otherwise to propagate or modify it is void, and 400 | will automatically terminate your rights under this License (including any 401 | patent licenses granted under the third paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your license from a 404 | particular copyright holder is reinstated (a) provisionally, unless and until 405 | the copyright holder explicitly and finally terminates your license, and (b) 406 | permanently, if the copyright holder fails to notify you of the violation by 407 | some reasonable means prior to 60 days after the cessation. 408 | 409 | Moreover, your license from a particular copyright holder is reinstated 410 | permanently if the copyright holder notifies you of the violation by some 411 | reasonable means, this is the first time you have received notice of violation 412 | of this License (for any work) from that copyright holder, and you cure the 413 | violation prior to 30 days after your receipt of the notice. 414 | 415 | Termination of your rights under this section does not terminate the licenses of 416 | parties who have received copies or rights from you under this License. If your 417 | rights have been terminated and not permanently reinstated, you do not qualify 418 | to receive new licenses for the same material under section 10. 419 | 420 | 421 | ### 9. Acceptance Not Required for Having Copies. 422 | 423 | You are not required to accept this License in order to receive or run a copy of 424 | the Program. Ancillary propagation of a covered work occurring solely as a 425 | consequence of using peer-to-peer transmission to receive a copy likewise does 426 | not require acceptance. However, nothing other than this License grants you 427 | permission to propagate or modify any covered work. These actions infringe 428 | copyright if you do not accept this License. Therefore, by modifying or 429 | propagating a covered work, you indicate your acceptance of this License to do 430 | so. 431 | 432 | 433 | ### 10. Automatic Licensing of Downstream Recipients. 434 | 435 | Each time you convey a covered work, the recipient automatically receives a 436 | license from the original licensors, to run, modify and propagate that work, 437 | subject to this License. You are not responsible for enforcing compliance by 438 | third parties with this License. 439 | 440 | An "entity transaction" is a transaction transferring control of an 441 | organization, or substantially all assets of one, or subdividing an 442 | organization, or merging organizations. If propagation of a covered work results 443 | from an entity transaction, each party to that transaction who receives a copy 444 | of the work also receives whatever licenses to the work the party's predecessor 445 | in interest had or could give under the previous paragraph, plus a right to 446 | possession of the Corresponding Source of the work from the predecessor in 447 | interest, if the predecessor has it or can get it with reasonable efforts. 448 | 449 | You may not impose any further restrictions on the exercise of the rights 450 | granted or affirmed under this License. For example, you may not impose a 451 | license fee, royalty, or other charge for exercise of rights granted under this 452 | License, and you may not initiate litigation (including a cross-claim or 453 | counterclaim in a lawsuit) alleging that any patent claim is infringed by 454 | making, using, selling, offering for sale, or importing the Program or any 455 | portion of it. 456 | 457 | 458 | ### 11. Patents. 459 | 460 | A "contributor" is a copyright holder who authorizes use under this License of 461 | the Program or a work on which the Program is based. The work thus licensed is 462 | called the contributor's "contributor version". 463 | 464 | A contributor's "essential patent claims" are all patent claims owned or 465 | controlled by the contributor, whether already acquired or hereafter acquired, 466 | that would be infringed by some manner, permitted by this License, of making, 467 | using, or selling its contributor version, but do not include claims that would 468 | be infringed only as a consequence of further modification of the contributor 469 | version. For purposes of this definition, "control" includes the right to grant 470 | patent sublicenses in a manner consistent with the requirements of this License. 471 | 472 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent 473 | license under the contributor's essential patent claims, to make, use, sell, 474 | offer for sale, import and otherwise run, modify and propagate the contents of 475 | its contributor version. 476 | 477 | In the following three paragraphs, a "patent license" is any express agreement 478 | or commitment, however denominated, not to enforce a patent (such as an express 479 | permission to practice a patent or covenant not to sue for patent infringement). 480 | To "grant" such a patent license to a party means to make such an agreement or 481 | commitment not to enforce a patent against the party. 482 | 483 | If you convey a covered work, knowingly relying on a patent license, and the 484 | Corresponding Source of the work is not available for anyone to copy, free of 485 | charge and under the terms of this License, through a publicly available network 486 | server or other readily accessible means, then you must either (1) cause the 487 | Corresponding Source to be so available, or (2) arrange to deprive yourself of 488 | the benefit of the patent license for this particular work, or (3) arrange, in a 489 | manner consistent with the requirements of this License, to extend the patent 490 | license to downstream recipients. "Knowingly relying" means you have actual 491 | knowledge that, but for the patent license, your conveying the covered work in a 492 | country, or your recipient's use of the covered work in a country, would 493 | infringe one or more identifiable patents in that country that you have reason 494 | to believe are valid. 495 | 496 | If, pursuant to or in connection with a single transaction or arrangement, you 497 | convey, or propagate by procuring conveyance of, a covered work, and grant a 498 | patent license to some of the parties receiving the covered work authorizing 499 | them to use, propagate, modify or convey a specific copy of the covered work, 500 | then the patent license you grant is automatically extended to all recipients of 501 | the covered work and works based on it. 502 | 503 | A patent license is "discriminatory" if it does not include within the scope of 504 | its coverage, prohibits the exercise of, or is conditioned on the non- exercise 505 | of one or more of the rights that are specifically granted under this License. 506 | You may not convey a covered work if you are a party to an arrangement with a 507 | third party that is in the business of distributing software, under which you 508 | make payment to the third party based on the extent of your activity of 509 | conveying the work, and under which the third party grants, to any of the 510 | parties who would receive the covered work from you, a discriminatory patent 511 | license (a) in connection with copies of the covered work conveyed by you (or 512 | copies made from those copies), or (b) primarily for and in connection with 513 | specific products or compilations that contain the covered work, unless you 514 | entered into that arrangement, or that patent license was granted, prior to 28 515 | March 2007. 516 | 517 | Nothing in this License shall be construed as excluding or limiting any implied 518 | license or other defenses to infringement that may otherwise be available to you 519 | under applicable patent law. 520 | 521 | 522 | ### 12. No Surrender of Others' Freedom. 523 | 524 | If conditions are imposed on you (whether by court order, agreement or 525 | otherwise) that contradict the conditions of this License, they do not excuse 526 | you from the conditions of this License. If you cannot convey a covered work so 527 | as to satisfy simultaneously your obligations under this License and any other 528 | pertinent obligations, then as a consequence you may not convey it at all. For 529 | example, if you agree to terms that obligate you to collect a royalty for 530 | further conveying from those to whom you convey the Program, the only way you 531 | could satisfy both those terms and this License would be to refrain entirely 532 | from conveying the Program. 533 | 534 | 535 | ### 13. Use with the GNU Affero General Public License. 536 | 537 | Notwithstanding any other provision of this License, you have permission to link 538 | or combine any covered work with a work licensed under version 3 of the GNU 539 | Affero General Public License into a single combined work, and to convey the 540 | resulting work. The terms of this License will continue to apply to the part 541 | which is the covered work, but the special requirements of the GNU Affero 542 | General Public License, section 13, concerning interaction through a network 543 | will apply to the combination as such. 544 | 545 | 546 | ### 14. Revised Versions of this License. 547 | 548 | The Free Software Foundation may publish revised and/or new versions of the GNU 549 | General Public License from time to time. Such new versions will be similar in 550 | spirit to the present version, but may differ in detail to address new problems 551 | or concerns. 552 | 553 | Each version is given a distinguishing version number. If the Program specifies 554 | that a certain numbered version of the GNU General Public License "or any later 555 | version" applies to it, you have the option of following the terms and 556 | conditions either of that numbered version or of any later version published by 557 | the Free Software Foundation. If the Program does not specify a version number 558 | of the GNU General Public License, you may choose any version ever published by 559 | the Free Software Foundation. 560 | 561 | If the Program specifies that a proxy can decide which future versions of the 562 | GNU General Public License can be used, that proxy's public statement of 563 | acceptance of a version permanently authorizes you to choose that version for 564 | the Program. 565 | 566 | Later license versions may give you additional or different permissions. 567 | However, no additional obligations are imposed on any author or copyright holder 568 | as a result of your choosing to follow a later version. 569 | 570 | 571 | ### 15. Disclaimer of Warranty. 572 | 573 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 574 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER 575 | PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER 576 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 577 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE 578 | QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 579 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 580 | 581 | 582 | ### 16. Limitation of Liability. 583 | 584 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY 585 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS 586 | PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, 587 | INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE 588 | THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED 589 | INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE 590 | PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY 591 | HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 592 | 593 | ### 17. Interpretation of Sections 15 and 16. 594 | 595 | If the disclaimer of warranty and limitation of liability provided above cannot 596 | be given local legal effect according to their terms, reviewing courts shall 597 | apply local law that most closely approximates an absolute waiver of all civil 598 | liability in connection with the Program, unless a warranty or assumption of 599 | liability accompanies a copy of the Program in return for a fee. 600 | 601 | END OF TERMS AND CONDITIONS 602 | 603 | 604 | How to Apply These Terms to Your New Programs 605 | --------------------------------------------- 606 | 607 | If you develop a new program, and you want it to be of the greatest possible use 608 | to the public, the best way to achieve this is to make it free software which 609 | everyone can redistribute and change under these terms. 610 | 611 | To do so, attach the following notices to the program. It is safest to attach 612 | them to the start of each source file to most effectively state the exclusion of 613 | warranty; and each file should have at least the "copyright" line and a pointer 614 | to where the full notice is found. 615 | 616 | 617 | Copyright (C) 618 | 619 | This program is free software: you can redistribute it and/or modify it 620 | under the terms of the GNU General Public License as published by the Free 621 | Software Foundation, either version 3 of the License, or (at your option) 622 | any later version. 623 | 624 | This program is distributed in the hope that it will be useful, but WITHOUT 625 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 626 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 627 | more details. 628 | 629 | You should have received a copy of the GNU General Public License along with 630 | this program. If not, see . 631 | 632 | Also add information on how to contact you by electronic and paper mail. 633 | 634 | If the program does terminal interaction, make it output a short notice like 635 | this when it starts in an interactive mode: 636 | 637 | Copyright (C) 638 | This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. 639 | This is free software, and you are welcome to redistribute it under certain 640 | conditions; type 'show c' for details. 641 | 642 | The hypothetical commands 'show w' and 'show c' should show the appropriate 643 | parts of the General Public License. Of course, your program's commands might be 644 | different; for a GUI interface, you would use an "about box". 645 | 646 | You should also get your employer (if you work as a programmer) or school, if 647 | any, to sign a "copyright disclaimer" for the program, if necessary. For more 648 | information on this, and how to apply and follow the GNU GPL, see 649 | <>. 650 | 651 | The GNU General Public License does not permit incorporating your program into 652 | proprietary programs. If your program is a subroutine library, you may consider 653 | it more useful to permit linking proprietary applications with the library. If 654 | this is what you want to do, use the GNU Lesser General Public License instead 655 | of this License. But first, please read 656 | <>. 657 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Centr 2 | There are millions of services out there. Each one comes with an extra dashboard. Centr aims to combine the dashboard of all services. Also Centr should be easily extensible for new services. 3 | 4 | ![Image of Centr](/centr.png?raw=true) 5 | 6 | # Features 7 | ## Included Services: 8 | - RSS Feed support 9 | - Soundcloud (partly WIP (see TODO)) 10 | - Reddit (partly WIP (see TODO)) 11 | - GitHub 12 | 13 | ## Other Features: 14 | - KeePass Connection 15 | 16 | # Install and Run 17 | 1. `pip install -r requirements.txt` 18 | 2. `python main.py db upgrade` 19 | 3. `python main.py runserver` 20 | 21 | **OR** 22 | 23 | ## For Linux: 24 | 1. `./install_and_run.sh` 25 | 26 | ## For Windows: 27 | 1. `install_and_run.bat` 28 | 29 | # Contribute 30 | You can contribute by adding issues and suggesting new services. Or you simply fork and make pull requests. 31 | 32 | #TODO 33 | [ ] Soundcloud (implement cards for comment) 34 | 35 | [ ] Soundcloud (implement cards for favoriting) 36 | 37 | [ ] Reddit (implement user login -> monitor new mails (new comments and new upvotes)) 38 | 39 | [ ] Implement infinity-scroll? 40 | 41 | [ ] Performance fixes (away from prerendered templates to real web technology?) 42 | 43 | # License 44 | Centr is licensed under the GNU General Public License version 3. 45 | The text of the GNU General Public License can be viewed at http://www.gnu.org/licenses/gpl.html 46 | See LICENSE.md file. 47 | -------------------------------------------------------------------------------- /centr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/centr.png -------------------------------------------------------------------------------- /config_template.py: -------------------------------------------------------------------------------- 1 | import os 2 | import keepass 3 | 4 | with open('') as f: 5 | content = f.readlines() 6 | 7 | basedir = os.path.abspath(os.path.dirname(__file__)) # ') 9 | 10 | extract = keepass.KeePassExtract(databasefile, content[0]) 11 | 12 | SHOW_LINKS = True # indicates whether or not a link to the source side should be shown on the dashboard 13 | DEBUG = False # run the server in debug mode? 14 | 15 | entry = extract.get_entry('github') 16 | 17 | github = { 18 | 'username': '', # or entry.username, 19 | 'password': '', # or entry.password, 20 | 'max_count': , 21 | 'accepted_types': { 22 | 'CommitCommentEvent': True, 23 | 'CreateEvent': True, 24 | 'DeleteEvent': True, 25 | 'ForkEvent': True, 26 | 'GollumEvent': True, 27 | 'IssueCommentEvent': True, 28 | 'IssuesEvent': True, 29 | 'MemberEvent': True, 30 | 'PublicEvent': True, 31 | 'PullRequestEvent': True, 32 | 'PullRequestReviewCommentEvent': True, 33 | 'PushEvent': True, 34 | 'ReleaseEvent': True, 35 | 'WatchEvent': True, 36 | } 37 | } 38 | 39 | reddit = { 40 | 'subreddits': [ 41 | {'name': '', 'max_count': }, 42 | ], 43 | 'users': [ 44 | {'name': '', 'max_count': }, 45 | ], 46 | } 47 | 48 | rss = [ 49 | { 50 | 'name': '', 51 | 'url': '', 52 | 'max_count': 5, # 53 | }, 54 | ] 55 | 56 | entry = extract.get_entry('runtastic') 57 | 58 | runtastic = { 59 | 'username': '--', 60 | 'user': '', # or entry.username 61 | 'password': '', # or entry.password 62 | } 63 | 64 | entry = extract.get_entry('soundcloud') 65 | 66 | soundcloud = { 67 | 'client_id': '', 68 | 'client_secret': '', 69 | 'username': '', # or entry.username 70 | 'password': '', # or entry.password 71 | 'max_count': 5, # , 72 | 'accepted_types': { 73 | 'track': True, 74 | 'track-repost': True, 75 | 'comment': True, 76 | 'favoriting': True 77 | }, 78 | } 79 | -------------------------------------------------------------------------------- /db.py: -------------------------------------------------------------------------------- 1 | from flask_sqlalchemy import SQLAlchemy 2 | from sqlalchemy.orm import scoped_session, sessionmaker 3 | from sqlalchemy import or_ 4 | from sqlalchemy import exc 5 | import datetime 6 | import logging 7 | from main import database as db 8 | from feeditem import Feeditem 9 | 10 | class DBFeedItem(db.Model): 11 | id = db.Column(db.Integer, primary_key = True) 12 | content = db.Column(db.Text) 13 | type = db.Column(db.String(20)) 14 | source = db.Column(db.String(125)) 15 | time = db.Column(db.DateTime) 16 | link = db.Column(db.Text) 17 | 18 | __table_args__ = ( 19 | db.UniqueConstraint('content', 'source', name = 'uk_content_source'), 20 | ) 21 | 22 | def __init__(self, content, type, source, time, link = ""): 23 | self.content = content 24 | self.type = type 25 | self.source = source 26 | self.time = time 27 | self.link = link 28 | 29 | def __repr__(self): 30 | return 'DBFeedItem ID: ' + str(self.id) 31 | 32 | class DBConnection: 33 | 34 | _logger = logging.getLogger('DBConnection') 35 | 36 | def __init__(self): 37 | self.session = sessionmaker() 38 | 39 | def insert_element(self, element): 40 | s = db.session 41 | 42 | if isinstance(element, DBFeedItem): 43 | try: 44 | s.add(element) 45 | s.commit() 46 | except exc.IntegrityError, e: 47 | # we expect integrity errors. The reason is that we may try to regularly insert the same element into the database 48 | # those elements should not be added to the database and we just rollback the transaction and don't log anything 49 | s.rollback() 50 | except Exception, e: 51 | self._logger.error(str(e)) 52 | s.rollback() 53 | elif isinstance(element, Feeditem): 54 | self.insert_element(DBFeedItem(element.content, element.type, element.source, element.time)) 55 | else: 56 | self._logger.warning('An element could not be inserted into the database, because it is non of the accepted types. (' + type(element) + ')') 57 | 58 | def get_feeds(self, type): 59 | s = db.session 60 | return s.query(DBFeedItem).filter(DBFeedItem.type == type).order_by(DBFeedItem.time.desc()) 61 | -------------------------------------------------------------------------------- /feeditem.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | class Feeditem: 4 | def __init__(self, content, type, source, time, link = ""): 5 | self.content = content 6 | self.type = type 7 | self.source = source 8 | self.time = time 9 | self.link = link 10 | 11 | def get(self): 12 | return { 13 | 'content': self.content, 14 | 'type': self.type, 15 | 'source': self.source, 16 | 'time': str(self.time), 17 | 'link': self.link 18 | } 19 | -------------------------------------------------------------------------------- /install_and_run.bat: -------------------------------------------------------------------------------- 1 | pip install -r requirements.txt 2 | python main.py db upgrade 3 | python main.py runserver 4 | -------------------------------------------------------------------------------- /install_and_run.sh: -------------------------------------------------------------------------------- 1 | pip install -r requirements.txt 2 | python main.py db upgrade 3 | python main.py runserver 4 | -------------------------------------------------------------------------------- /keepass.py: -------------------------------------------------------------------------------- 1 | import libkeepass 2 | import logging 3 | 4 | class KeePassExtract(): 5 | 6 | _logger = logging.getLogger('keypassextract') 7 | 8 | def __init__(self, databasefile_, password_): 9 | self.databasefile = databasefile_ 10 | self.password = password_ 11 | 12 | def get_entry(self, title): 13 | if self.databasefile == None or self.password == None: 14 | self._logger.error('Not initialized...') 15 | return None 16 | 17 | with libkeepass.open(self.databasefile, password = self.password) as kdb: 18 | found = False 19 | for entry in kdb.obj_root.findall('.//Entry'): 20 | for string in entry.findall('.//String'): 21 | if string.find('.//Key') != 'Title': 22 | continue 23 | if string.find('.//Value') == title: 24 | found = True 25 | break 26 | 27 | if found: 28 | for sting in entry.findall('.//String'): 29 | if sting.find('.//Key') == 'Notes': 30 | notes = sting.find('.//Value') 31 | elif sting.find('.//Key') == 'Password': 32 | password = sting.find('.//Value') 33 | elif sting.find('.//Key') == 'Title': 34 | title = sting.find('.//Value') 35 | elif sting.find('.//Key') == 'URL': 36 | url = sting.find('.//Value') 37 | elif sting.find('.//Key') == 'UserName': 38 | username = sting.find('.//Value') 39 | return KeePassEntry(notes, password, title, url, username) 40 | 41 | return None 42 | 43 | class KeePassEntry(): 44 | def __init__(self, notes, password, title, url, username): 45 | self.notes = notes 46 | self.password = password 47 | self.title = title 48 | self.url = url 49 | self.username = username 50 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, render_template 2 | from flaskext.markdown import Markdown 3 | from flask_migrate import Migrate, MigrateCommand 4 | from flask_sqlalchemy import SQLAlchemy 5 | from sqlalchemy import create_engine 6 | from flask_script import Manager 7 | import datetime 8 | import threading 9 | import time 10 | import logging 11 | logging.basicConfig() 12 | import os 13 | import config 14 | from feeditem import Feeditem 15 | 16 | app = Flask(__name__) 17 | 18 | basedir = os.path.abspath(os.path.dirname(__file__)) 19 | app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + basedir + '/app.db' 20 | app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True 21 | app.debug = config.DEBUG 22 | 23 | engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'], convert_unicode = True) 24 | database = SQLAlchemy(app) 25 | _logger = logging.getLogger() 26 | 27 | 28 | migrate = Migrate(app, database) 29 | manager = Manager(app) 30 | manager.add_command('db', MigrateCommand) 31 | 32 | Markdown(app) 33 | 34 | @manager.command 35 | def runserver(): 36 | app.run(host = '0.0.0.0') 37 | 38 | addons = [] 39 | 40 | @app.template_filter('datetime') 41 | def _jinja2_filter_datetime(date): 42 | return date.strftime('%d.%m.%Y') 43 | 44 | @app.route("/") 45 | def main_route(): 46 | 47 | from db import DBFeedItem, DBConnection 48 | 49 | conn = DBConnection() 50 | 51 | feeditems = [] 52 | addonitems = [] 53 | 54 | if addons == None: 55 | _logger.info('No addon loaded...') 56 | return 57 | 58 | _logger.info(str(len(addons)) + ' addons loaded...') 59 | 60 | for addon in addons: 61 | if hasattr(addon, 'get_feeds'): 62 | feeds = getattr(addon, 'get_feeds')() 63 | else: 64 | _logger.warn('The addon ' + str(addon) + ' is not supported. Please implement a "get_feeds()" function or contact the developer.') 65 | continue 66 | 67 | if feeds == None or len(feeds) == 0: 68 | continue 69 | 70 | addonitems.append(feeds[0].type) 71 | 72 | for feed in feeds: 73 | if isinstance(feed, Feeditem) or isinstance(feed, DBFeedItem): 74 | feeditems.append(feed) 75 | else: 76 | _logger.warn('The element (' + str(feed) + ') could not be placed on the stream.') 77 | 78 | feeditems.sort(key = lambda element: element.time, reverse = True) 79 | 80 | return render_template('dashboard.html', 81 | feeditems = feeditems, 82 | addonitems = addonitems, 83 | extended = config.SHOW_LINKS, 84 | date = datetime.datetime.utcnow() 85 | ) 86 | 87 | def __load_all_modules(): 88 | ''' 89 | Load all modules from the modules folder. 90 | ''' 91 | import modules.__init__ 92 | import importlib 93 | 94 | _logger.info('Start to load the modules...') 95 | 96 | for addon in modules.__init__.__all__: 97 | module = importlib.import_module('.' + addon, 'modules') 98 | 99 | addons.append(module) 100 | thread = FetchThread(str(addon), module) 101 | thread.setDaemon(True) 102 | thread.start() 103 | 104 | 105 | class FetchThread(threading.Thread): 106 | 107 | _logger = None 108 | 109 | def __init__(self, name, module): 110 | threading.Thread.__init__(self) 111 | self.name = name 112 | self.module = module 113 | self._logger = logging.getLogger(self.name) 114 | 115 | def run(self): 116 | if hasattr(self.module, '_load_feeds'): 117 | while True: 118 | self.module._load_feeds() 119 | time.sleep(300) # every 5 minutes 120 | else: 121 | self._logger.warning('The addon ' + str(self.name) + ' does not implement the "_load_feeds()" function.') 122 | 123 | 124 | if __name__ == "__main__": 125 | __load_all_modules() 126 | database.create_all() 127 | manager.run() 128 | -------------------------------------------------------------------------------- /migrations/README: -------------------------------------------------------------------------------- 1 | Generic single-database configuration. -------------------------------------------------------------------------------- /migrations/alembic.ini: -------------------------------------------------------------------------------- 1 | # A generic, single database configuration. 2 | 3 | [alembic] 4 | # template used to generate migration files 5 | # file_template = %%(rev)s_%%(slug)s 6 | 7 | # set to 'true' to run the environment during 8 | # the 'revision' command, regardless of autogenerate 9 | # revision_environment = false 10 | 11 | 12 | # Logging configuration 13 | [loggers] 14 | keys = root,sqlalchemy,alembic 15 | 16 | [handlers] 17 | keys = console 18 | 19 | [formatters] 20 | keys = generic 21 | 22 | [logger_root] 23 | level = WARN 24 | handlers = console 25 | qualname = 26 | 27 | [logger_sqlalchemy] 28 | level = WARN 29 | handlers = 30 | qualname = sqlalchemy.engine 31 | 32 | [logger_alembic] 33 | level = INFO 34 | handlers = 35 | qualname = alembic 36 | 37 | [handler_console] 38 | class = StreamHandler 39 | args = (sys.stderr,) 40 | level = NOTSET 41 | formatter = generic 42 | 43 | [formatter_generic] 44 | format = %(levelname)-5.5s [%(name)s] %(message)s 45 | datefmt = %H:%M:%S 46 | -------------------------------------------------------------------------------- /migrations/env.py: -------------------------------------------------------------------------------- 1 | from __future__ import with_statement 2 | from alembic import context 3 | from sqlalchemy import engine_from_config, pool 4 | from logging.config import fileConfig 5 | import logging 6 | 7 | # this is the Alembic Config object, which provides 8 | # access to the values within the .ini file in use. 9 | config = context.config 10 | 11 | # Interpret the config file for Python logging. 12 | # This line sets up loggers basically. 13 | fileConfig(config.config_file_name) 14 | logger = logging.getLogger('alembic.env') 15 | 16 | # add your model's MetaData object here 17 | # for 'autogenerate' support 18 | # from myapp import mymodel 19 | # target_metadata = mymodel.Base.metadata 20 | from flask import current_app 21 | config.set_main_option('sqlalchemy.url', 22 | current_app.config.get('SQLALCHEMY_DATABASE_URI')) 23 | target_metadata = current_app.extensions['migrate'].db.metadata 24 | 25 | # other values from the config, defined by the needs of env.py, 26 | # can be acquired: 27 | # my_important_option = config.get_main_option("my_important_option") 28 | # ... etc. 29 | 30 | 31 | def run_migrations_offline(): 32 | """Run migrations in 'offline' mode. 33 | 34 | This configures the context with just a URL 35 | and not an Engine, though an Engine is acceptable 36 | here as well. By skipping the Engine creation 37 | we don't even need a DBAPI to be available. 38 | 39 | Calls to context.execute() here emit the given string to the 40 | script output. 41 | 42 | """ 43 | url = config.get_main_option("sqlalchemy.url") 44 | context.configure(url=url) 45 | 46 | with context.begin_transaction(): 47 | context.run_migrations() 48 | 49 | 50 | def run_migrations_online(): 51 | """Run migrations in 'online' mode. 52 | 53 | In this scenario we need to create an Engine 54 | and associate a connection with the context. 55 | 56 | """ 57 | 58 | # this callback is used to prevent an auto-migration from being generated 59 | # when there are no changes to the schema 60 | # reference: http://alembic.readthedocs.org/en/latest/cookbook.html 61 | def process_revision_directives(context, revision, directives): 62 | if getattr(config.cmd_opts, 'autogenerate', False): 63 | script = directives[0] 64 | if script.upgrade_ops.is_empty(): 65 | directives[:] = [] 66 | logger.info('No changes in schema detected.') 67 | 68 | engine = engine_from_config(config.get_section(config.config_ini_section), 69 | prefix='sqlalchemy.', 70 | poolclass=pool.NullPool) 71 | 72 | connection = engine.connect() 73 | context.configure(connection=connection, 74 | target_metadata=target_metadata, 75 | process_revision_directives=process_revision_directives, 76 | **current_app.extensions['migrate'].configure_args) 77 | 78 | try: 79 | with context.begin_transaction(): 80 | context.run_migrations() 81 | finally: 82 | connection.close() 83 | 84 | if context.is_offline_mode(): 85 | run_migrations_offline() 86 | else: 87 | run_migrations_online() 88 | -------------------------------------------------------------------------------- /migrations/script.py.mako: -------------------------------------------------------------------------------- 1 | """${message} 2 | 3 | Revision ID: ${up_revision} 4 | Revises: ${down_revision} 5 | Create Date: ${create_date} 6 | 7 | """ 8 | 9 | # revision identifiers, used by Alembic. 10 | revision = ${repr(up_revision)} 11 | down_revision = ${repr(down_revision)} 12 | 13 | from alembic import op 14 | import sqlalchemy as sa 15 | ${imports if imports else ""} 16 | 17 | def upgrade(): 18 | ${upgrades if upgrades else "pass"} 19 | 20 | 21 | def downgrade(): 22 | ${downgrades if downgrades else "pass"} 23 | -------------------------------------------------------------------------------- /migrations/versions/8a3e1e2_initial_model.py: -------------------------------------------------------------------------------- 1 | """initial model 2 | 3 | Revision ID: 8a3e1e2 4 | Revises: None 5 | Create Date: 2016-02-16 10:40 6 | """ 7 | 8 | from alembic import op 9 | import sqlalchemy as sa 10 | from sqlalchemy.sql import expression 11 | 12 | # revision identifiers, used by Alembic. 13 | revision = "8a3e1e2" 14 | down_revision = None 15 | 16 | 17 | def upgrade(): 18 | op.create_table("db_log_item", 19 | sa.Column("id", sa.Integer, primary_key = True), 20 | sa.Column("message", sa.Text), 21 | sa.Column("time", sa.DateTime), 22 | sa.Column("level", sa.String(5)), 23 | sa.Column("trace", sa.Text), 24 | ) 25 | op.create_table("db_feed_item", 26 | sa.Column("id", sa.Integer, primary_key = True), 27 | sa.Column("content", sa.Text), 28 | sa.Column("type", sa.String(20)), 29 | sa.Column("source", sa.String(125)), 30 | sa.Column("time", sa.DateTime), 31 | sa.UniqueConstraint('content', 'source', name = 'uk_content_source'), 32 | ) 33 | 34 | 35 | def downgrade(): 36 | op.drop_table("DBLogItem") 37 | op.drop_table("DBFeedItem") 38 | -------------------------------------------------------------------------------- /migrations/versions/e2300a5_new_link_item.py: -------------------------------------------------------------------------------- 1 | """new link column for each feed item 2 | 3 | Revision ID: e2300a5 4 | Revises: None 5 | Create Date: 2016-02-26 16:27 6 | """ 7 | 8 | from alembic import op 9 | import sqlalchemy as sa 10 | from sqlalchemy.sql import expression 11 | 12 | # revision identifiers, used by Alembic. 13 | revision = "e2300a5" 14 | down_revision = "8a3e1e2" 15 | 16 | 17 | def upgrade(): 18 | op.add_column("db_feed_item", 19 | sa.Column("link", sa.Text, server_default = "") 20 | ) 21 | 22 | 23 | def downgrade(): 24 | op.drop_column("db_feed_item", "link") 25 | -------------------------------------------------------------------------------- /modules/__init__.py: -------------------------------------------------------------------------------- 1 | from os.path import dirname, basename, isfile 2 | import glob 3 | modules = glob.glob(dirname(__file__)+"/*.py") 4 | __all__ = [ basename(f)[:-3] for f in modules if isfile(f)] 5 | __all__.remove('__init__') 6 | -------------------------------------------------------------------------------- /modules/m_github.py: -------------------------------------------------------------------------------- 1 | from config import github as config 2 | from db import DBFeedItem, DBConnection 3 | from github3 import GitHub 4 | from requests.exceptions import ConnectionError 5 | import logging 6 | import datetime 7 | 8 | gh = GitHub(config['username'], config['password']) 9 | events = gh.user(config['username']).iter_received_events(public = True) 10 | 11 | TYPE = 'github' 12 | 13 | _logger = logging.getLogger(TYPE) 14 | conn = DBConnection() 15 | 16 | accepted_types = [m for m in config['accepted_types'] if config['accepted_types'][m] == True] 17 | type_header_map = { 18 | 'CommitCommentEvent': '{event.actor.login} commented on commit {event.repo[0]}/{event.repo[1]}@{rev_10}', 19 | 'CreateEvent': '{event.actor.login} created {ref_type} {var_created}', 20 | # 'DeleteEvent': 'A {ref_type} was deleted.', # TODO: format like github does 21 | 'ForkEvent': '{event.actor.login} forked {event.repo[0]}/{event.repo[1]} to {forkee.full_name}', 22 | 'GollumEvent': '{event.actor.login} edited the {event.repo[0]}/{event.repo[1]} wiki', 23 | 'IssueCommentEvent': '{event.actor.login} commented on issue {event.repo[0]}/{event.repo[1]}#{issue.number}', 24 | 'IssuesEvent': '{event.actor.login} {action} issue {event.repo[0]}/{event.repo[1]}#{issue.number}', 25 | 'MemberEvent': '{event.actor.login} {action} {added_user.login} to {event.repo[0]}/{event.repo[1]}', 26 | 'PublicEvent': '{event.actor.login} made {event.repo[0]}/{event.repo[1]} public', 27 | 'PullRequestEvent': '{event.actor.login} {action} pull request {event.repo[0]}/{event.repo[1]}#{number}', 28 | 'PullRequestReviewCommentEvent': '{event.actor.login} commented on pull request {event.repo[0]}/{event.repo[1]}#{number}', 29 | 'PushEvent': '{event.actor.login} pushed to {ref} at {event.repo[0]}/{event.repo[1]}', 30 | # 'ReleaseEvent': 'A new comment was given on a commit.', # TODO: format like github does 31 | 'WatchEvent': '{event.actor.login} starred {event.repo[0]}/{event.repo[1]}', 32 | } 33 | 34 | def __get_link(event): 35 | return event.payload['comment'].html_url if 'comment' in event.payload and hasattr(event.payload['comment'], 'html_url') and event.payload['comment'].html_url != '' \ 36 | else event.payload['issue'].html_url if 'issue' in event.payload and hasattr(event.payload['issue'], 'html_url') and event.payload['issue'].html_url != '' \ 37 | else event.payload['release'].html_url if 'release' in event.payload and hasattr(event.payload['release'], 'html_url') and event.payload['release'].html_url != '' \ 38 | else event.payload['pull_request'].html_url if 'pull_request' in event.payload and hasattr(event.payload['pull_request'], 'html_url') and event.payload['pull_request'].html_url != '' \ 39 | else event.payload['html_url'] + '/wiki' if 'html_url' in event.payload and event.type == 'GollumEvent' \ 40 | else event.payload['html_url'] + '/commits' if 'html_url' in event.payload and event.type == 'PushEvent' \ 41 | else event.payload['forkee'].html_url if 'forkee' in event.payload and hasattr(event.payload['forkee'], 'html_url') and event.payload['forkee'].html_url != '' \ 42 | else event.payload['html_url'] if 'html_url' in event.payload else None # more or less a fallback. as far as i saw every payload got this field. 43 | 44 | def get_feeds(): 45 | result = [] 46 | count = 0 47 | for feed in conn.get_feeds(TYPE): 48 | if count >= config['max_count']: 49 | break 50 | result.append(feed) 51 | count += 1 52 | return result 53 | 54 | def _load_feeds(): 55 | _logger.debug('Started to load feeds') 56 | try: 57 | for event in events: 58 | if event.type not in type_header_map: 59 | _logger.info('Unrecognised event: ' + str(event)) 60 | continue 61 | 62 | if event.type not in accepted_types: 63 | continue 64 | 65 | payload = None 66 | if 'ref' in event.payload and event.payload['ref'] != None: 67 | payload = event.payload['ref'] 68 | 69 | source = type_header_map[event.type].format( 70 | event = event, 71 | action = event.payload['action'] if 'action' in event.payload else '', 72 | issue = event.payload['issue'] if 'issue' in event.payload else '', 73 | ref_type = event.payload['ref_type'] if 'ref_type' in event.payload else '', 74 | var_created = (str(event.payload['ref']) + ' at ' + event.repo[0] + '/' + event.repo[1]) if ('ref' in event.payload and event.payload['ref'] != None) 75 | else (event.repo[0] + '/' + event.repo[1]), 76 | forkee = event.payload['forkee'] if 'forkee' in event.payload else '', 77 | ref = payload[payload.rfind('/') + 1:] if (payload != None) else '', 78 | number = event.payload['number'] if 'number' in event.payload else '', 79 | rev_10 = event.payload['comment'].commit_id[:10] if ('comment' in event.payload and hasattr(event.payload['comment'], 'commit_id')) else '', 80 | added_user = event.payload['member'] if 'member' in event.payload else '', 81 | ) 82 | 83 | date = event.created_at 84 | link = __get_link(event) 85 | if isinstance(link, dict) and 'href' in link: 86 | link = link['href'] # sometimes we get a dict from github.. so we catch this and just take the link from the dict 87 | 88 | _logger.debug('Insert new element to database.') 89 | conn.insert_element( 90 | DBFeedItem( 91 | '', # content 92 | TYPE, # element type (soundcloud) 93 | source, # source (the type of the element from soundcloud) 94 | date, # time (as datetime) 95 | link, # link to source 96 | ) 97 | ) 98 | except ConnectionError, e: 99 | _logger.error(str(e)) 100 | -------------------------------------------------------------------------------- /modules/m_reddit.py: -------------------------------------------------------------------------------- 1 | import praw 2 | from datetime import datetime 3 | from time import mktime 4 | from config import reddit as config 5 | from db import DBConnection, DBFeedItem 6 | from feeditem import Feeditem 7 | from main import app 8 | import logging 9 | import json 10 | from requests.exceptions import ConnectionError 11 | 12 | TYPE = 'reddit' 13 | USERS = 'u' 14 | SUBREDDIT = 'r' 15 | 16 | _logger = logging.getLogger(TYPE) 17 | 18 | reddit_feeds = [] 19 | 20 | user_post_source_map = { 21 | 'submission': 'User {0} has posted on subreddit {1}', 22 | 'comment': 'User {0} commented on a post' 23 | } 24 | subreddit_action = 'New post in subreddit {0}' 25 | 26 | conn = DBConnection() 27 | reddit_conn = praw.Reddit(user_agent = 'centr') 28 | 29 | class RedditFeed: 30 | def __init__(self, name, source, max_count): 31 | self.name = name 32 | self.source = source 33 | self.max_count = max_count 34 | 35 | def get_feeds(): 36 | result = [] 37 | 38 | feedsources = [] 39 | feed_map = {} 40 | 41 | if reddit_feeds == []: 42 | return None 43 | 44 | count = 0 45 | for feed in reddit_feeds: 46 | feedsources.append({'src': feed.name, 'counter': 0, 'max_count': feed.max_count}) 47 | feed_map[feed.name] = count 48 | count += 1 49 | 50 | feeds = conn.get_feeds(TYPE) 51 | 52 | for feed in feeds: 53 | 54 | loaded_source = json.loads(feed.source) 55 | 56 | if loaded_source['title'] in [elem['src'] for elem in feedsources]: 57 | max_count = feedsources[feed_map[loaded_source['title']]]['max_count'] 58 | else: 59 | max_count = 0 60 | 61 | try: 62 | if max_count != -1 and feedsources[feed_map[loaded_source['title']]]['counter'] >= max_count: 63 | continue 64 | except KeyError, e: 65 | # if the feed source is no longer available in the config 66 | continue 67 | 68 | if 'source' in loaded_source: 69 | # We get a user (is it a comment or a post?) 70 | if loaded_source['source'] == 'comment': 71 | source = user_post_source_map[loaded_source['source']].format(loaded_source['title']) 72 | elif loaded_source['source'] == 'submission': 73 | source = user_post_source_map[loaded_source['source']].format(loaded_source['title'], loaded_source['subreddit']) 74 | else: 75 | source = subreddit_action.format(loaded_source['title']) 76 | 77 | content = json.loads(feed.content) 78 | 79 | #if hasattr(content, 'content') and len(content['content']) > 0: 80 | # content['content_first'] = '' 81 | # content['content_additional'] = '' 82 | # 83 | # counter = 0 84 | # for item in content['content'].split('/n/n'): 85 | # if counter >= 2: # only show 2 paragraphs 86 | # content['content_additional'] += item 87 | # else: 88 | # content['content_first'] += item 89 | # counter += 1 90 | 91 | result.append(Feeditem( 92 | content, 93 | TYPE, 94 | source, 95 | feed.time, 96 | feed.link 97 | )) 98 | feedsources[feed_map[loaded_source['title']]]['counter'] += 1 99 | 100 | return result 101 | 102 | def _load_feeds(): 103 | for element in reddit_feeds: 104 | if element.source == SUBREDDIT: 105 | try: 106 | posts = reddit_conn.get_subreddit(element.name).get_new() 107 | for post in posts: 108 | content = {'post_name': post.title} 109 | 110 | if hasattr(post, 'preview'): 111 | img = {'source': '', 'width': 0} 112 | preview = post.preview 113 | for image in preview['images'][0]['resolutions']: 114 | if image['width'] > 640: 115 | continue 116 | if image['width'] > img['width']: 117 | img['source'] = image['url'] 118 | img['width'] = image['width'] 119 | content['thumbnail'] = img['source'] 120 | 121 | if hasattr(post, 'body'): 122 | content['content'] = post.body 123 | elif hasattr(post, 'selftext'): 124 | content['content'] = post.selftext 125 | 126 | url = '' 127 | 128 | if hasattr(post, 'url'): 129 | url = post.url 130 | elif hasattr(post, 'permalink'): 131 | url = post.permalink 132 | 133 | conn.insert_element(DBFeedItem( 134 | json.dumps(content), # content 135 | TYPE, # type 136 | json.dumps({'title': element.name}), # source 137 | _get_date(post), # time 138 | url, # link 139 | )) 140 | except ConnectionError, e: 141 | _logger.error('There was an error with the connection. ' + str(e)) 142 | 143 | elif element.source == USERS: 144 | try: 145 | redditor = reddit_conn.get_redditor(element.name) 146 | for comment in redditor.get_overview(sort = 'new', time = 'all'): 147 | if isinstance(comment, praw.objects.Comment): 148 | source = 'comment' 149 | elif isinstance(comment, praw.objects.Submission): 150 | source = 'submission' 151 | else: 152 | continue 153 | 154 | content = {} 155 | 156 | if hasattr(comment, 'body'): 157 | content['content'] = comment.body 158 | elif hasattr(comment, 'selftext'): 159 | content['content'] = comment.selftext 160 | 161 | subreddit = '' 162 | if hasattr(comment, 'subreddit'): 163 | subreddit = comment.subreddit.name 164 | 165 | if hasattr(comment, 'title'): 166 | content['post_name'] = comment.title 167 | elif hasattr(comment, 'link_title'): 168 | content['post_name'] = comment.link_title 169 | else: 170 | continue 171 | 172 | url = '' 173 | 174 | if hasattr(comment, 'url'): 175 | url = comment.url 176 | elif hasattr(comment, 'permalink'): 177 | url = comment.permalink 178 | 179 | conn.insert_element(DBFeedItem( 180 | json.dumps(content), # content 181 | TYPE, # type 182 | json.dumps({'title': element.name, 'source': source, 'subreddit': subreddit}), # source 183 | _get_date(comment), # time 184 | url, # link 185 | )) 186 | 187 | except ConnectionError, e: 188 | _logger.error('There was an error with the connection. ' + str(e)) 189 | 190 | def reload_config(): 191 | if 'subreddits' in config: 192 | for reddititem in config['subreddits']: 193 | reddit_feeds.append(RedditFeed(reddititem['name'], SUBREDDIT, reddititem['max_count'])) 194 | if 'users' in config: 195 | for useritem in config['users']: 196 | reddit_feeds.append(RedditFeed(useritem['name'], USERS, useritem['max_count'])) 197 | 198 | reload_config() 199 | 200 | def _get_date(submission): 201 | time = submission.created_utc 202 | return datetime.fromtimestamp(time) 203 | -------------------------------------------------------------------------------- /modules/m_rss.py: -------------------------------------------------------------------------------- 1 | import feedparser 2 | import datetime 3 | import logging 4 | import config 5 | from db import DBConnection, DBFeedItem 6 | 7 | rssfeeds = [] 8 | 9 | TYPE = 'rss' 10 | DATE_FORMATS = ['%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%dT%H:%M:%S+00:00'] 11 | 12 | conn = DBConnection() 13 | 14 | class RSSFeed: 15 | def __init__(self, name, url, max_count): 16 | self.name = name 17 | self.url = url 18 | self.max_count = max_count 19 | 20 | def parse(self): 21 | return feedparser.parse(self.url) 22 | 23 | def get_feeds(): 24 | feeditems = [] 25 | 26 | feedsources = [] 27 | feed_map = {} 28 | 29 | # if no rss feeds in config return 30 | if rssfeeds == []: 31 | return None 32 | 33 | count = 0 34 | for feed in rssfeeds: 35 | feedsources.append({'src': 'A new post from ' + str(feed.name), 'counter': 0, 'max_count': feed.max_count}) 36 | feed_map['A new post from ' + str(feed.name)] = count 37 | count += 1 38 | 39 | # Iterate over all rss feed items and decide wether or not to add them to the mainline 40 | for item in conn.get_feeds(TYPE): 41 | 42 | if item.source in [elem['src'] for elem in feedsources]: 43 | max_count = feedsources[feed_map[item.source]]['max_count'] 44 | else: 45 | max_count = 0 46 | 47 | try: 48 | if max_count != -1 and feedsources[feed_map[item.source]]['counter'] >= max_count: 49 | continue 50 | except KeyError, e: 51 | # if the feed source is no longer available in the config 52 | continue 53 | 54 | feeditems.append(item) 55 | feedsources[feed_map[item.source]]['counter'] += 1 56 | 57 | return feeditems 58 | 59 | def _load_feeds(): 60 | reload_config() 61 | 62 | for rssfeed in rssfeeds: 63 | for entry in rssfeed.parse().entries: 64 | # parse loaded data 65 | content = '' 66 | 67 | if hasattr(entry, 'content') and hasattr(entry.content[0], 'value'): 68 | content = entry.content[0].value 69 | elif hasattr(entry, 'summary'): 70 | content = entry.summary 71 | elif hasattr(entry, 'description'): 72 | content = entry.description 73 | elif hasattr(entry, 'title'): 74 | content = entry.title 75 | 76 | if content == '': 77 | continue 78 | 79 | date = None 80 | 81 | if hasattr(entry, 'updated_parsed'): 82 | _date = entry.updated_parsed 83 | date = datetime.datetime( 84 | _date.tm_year, 85 | _date.tm_mon, 86 | _date.tm_mday, 87 | _date.tm_hour, 88 | _date.tm_min, 89 | _date.tm_sec 90 | ) 91 | 92 | if date == None: 93 | continue 94 | 95 | # insert into database 96 | conn.insert_element( 97 | DBFeedItem( 98 | content, 99 | TYPE, 100 | 'A new post from ' + str(rssfeed.name), 101 | date, 102 | entry.link, 103 | ) 104 | ) 105 | 106 | def reload_config(): 107 | for rssitem in config.rss: 108 | rssfeeds.append(RSSFeed(rssitem['name'], rssitem['url'], rssitem['max_count'])) 109 | 110 | reload_config() 111 | -------------------------------------------------------------------------------- /modules/m_runtastic.py: -------------------------------------------------------------------------------- 1 | # https://github.com/luser/runtastic-scrape 2 | 3 | import html5lib 4 | import json 5 | import os 6 | import re 7 | import sys 8 | import requests 9 | import urlparse 10 | 11 | def get_feeds(): 12 | pass 13 | 14 | known_sessions_file = os.path.join(os.path.dirname(__file__), 'known_sessions') 15 | 16 | def get_user_id(doc): 17 | script = [s for s in doc.getElementsByTagName('script') if not s.hasAttribute('src') and 'var user =' in s.firstChild.wholeText] 18 | if not script: 19 | raise 'Can\'t find user id script' 20 | m = re.search('\{.*\}', script[0].firstChild.wholeText) 21 | if not m: 22 | raise 'Can\'t find user id data' 23 | return int(json.loads(m.group(0))['id']) 24 | 25 | def get_data(doc): 26 | script = [s for s in doc.getElementsByTagName('script') if not s.hasAttribute('src') and 'var index_data =' in s.firstChild.wholeText] 27 | if not script: 28 | raise 'Can\'t find index_data script' 29 | m = re.search('\[.*\]', script[0].firstChild.wholeText) 30 | if not m: 31 | raise 'Can\'t find index_data data' 32 | return json.loads(m.group(0)) 33 | 34 | def get_csrf_token(doc): 35 | metas = doc.getElementsByTagName('meta') 36 | p = [m.getAttribute('content') for m in metas if m.getAttribute('name') == 'csrf-param'] 37 | if not p: 38 | print 'No csrf-param' 39 | token_name = None 40 | if p: 41 | token_name = p[0] 42 | v = [m.getAttribute('content') for m in metas if m.getAttribute('name') == 'csrf-token'] 43 | if not v: 44 | raise 'No csrf-token' 45 | token_value = v[0] 46 | return dict([(token_name, token_value)]) 47 | 48 | def read_known_sessions(): 49 | if not os.path.isfile(known_sessions_file): 50 | return set() 51 | with open(known_sessions_file, 'rb') as f: 52 | return set(int(s.strip()) for s in f.readlines()) 53 | 54 | def write_known_sessions(data): 55 | with open(known_sessions_file, 'wb') as f: 56 | f.write('\n'.join(str(s) for s in sorted(data))) 57 | 58 | def check_download_session(url, download_dir, cookies): 59 | r = requests.head(url, cookies=cookies) 60 | if r.status_code != 200 or 'Content-Disposition' not in r.headers: 61 | return False 62 | m = re.search('filename="(.+)"', r.headers['Content-Disposition']) 63 | if not m: 64 | return False 65 | f = m.group(1) 66 | filename = os.path.join(download_dir, f) 67 | if os.path.isfile(filename): 68 | return True 69 | # get it 70 | print "Fetching %s" % f 71 | r2 = requests.get(url, cookies=cookies) 72 | if r2.status_code != 200: 73 | return False 74 | with open(filename, 'wb') as f: 75 | f.write(r2.content) 76 | return True 77 | 78 | def fetch_data(user, pw, download_dir=None): 79 | # Fetch the index page to get a CSRF token. 80 | r = requests.get('https://www.runtastic.com/') 81 | if r.status_code != 200: 82 | raise 'Sucks' 83 | cookies = dict(r.cookies) 84 | doc = html5lib.parse(r.text, treebuilder='dom') 85 | csrf = get_csrf_token(doc) 86 | # Now log in. 87 | # user, pw = read_user_pass() 88 | login = dict(csrf) 89 | login['user[email]'] = user 90 | login['user[password]'] = pw 91 | login['grant_type'] = 'password' 92 | r2 = requests.post('https://www.runtastic.com/de/d/benutzer/sign_in', data=login)#, cookies=cookies) 93 | if r2.status_code != 200: 94 | raise 'Sucks 2' 95 | cookies.update(r2.cookies) 96 | print r2.content 97 | j = r2.json() 98 | if not j['success']: 99 | raise 'Login failed' 100 | doc = html5lib.parse(j['update'], treebuilder='dom') 101 | # Find the sport-sessions page and fetch it to get a User ID 102 | # and a list of session IDs. 103 | links = [l.getAttribute('href') for l in doc.getElementsByTagName('a') if l.getAttribute('href').endswith('/sport-sessions')] 104 | sessions_url = urlparse.urljoin(r2.url, links[0]) 105 | r3 = requests.get(sessions_url, cookies=cookies) 106 | if r3.status_code != 200: 107 | raise 'Sucks 3' 108 | cookies.update(r3.cookies) 109 | doc = html5lib.parse(r3.text, treebuilder='dom') 110 | uid = get_user_id(doc) 111 | data = get_data(doc) 112 | # Now hit the API to get data about each session. 113 | request_data = dict(csrf) 114 | request_data['user_id'] = uid 115 | request_data['items'] = ','.join(str(d[0]) for d in data) 116 | r4 = requests.post('https://www.runtastic.com/api/run_sessions/json', 117 | cookies=cookies, 118 | data=request_data) 119 | if r4.status_code != 200: 120 | raise 'Sucks 4' 121 | cookies.update(r4.cookies) 122 | sessions = r4.json() 123 | print sessions 124 | # known_sessions = read_known_sessions() 125 | # for s in sessions: 126 | # if s['id'] in known_sessions: 127 | # continue 128 | # if check_download_session(urlparse.urljoin(r4.url, s['page_url']) + '.tcx', download_dir, cookies): 129 | # known_sessions.add(s['id']) 130 | # write_known_sessions(known_sessions) 131 | 132 | def read_user_pass(): 133 | auth_file = os.path.join(os.path.dirname(__file__), 'auth') 134 | return [x.strip() for x in open(auth_file).read().splitlines()] 135 | -------------------------------------------------------------------------------- /modules/m_soundcloud.py: -------------------------------------------------------------------------------- 1 | import soundcloud 2 | import datetime 3 | import json 4 | from requests.exceptions import ConnectionError 5 | from config import soundcloud as config 6 | from db import DBConnection, DBFeedItem 7 | from feeditem import Feeditem 8 | 9 | TYPE = 'soundcloud' 10 | 11 | client = soundcloud.Client( 12 | client_id = config['client_id'], 13 | client_secret = config['client_secret'], 14 | username = config['username'], 15 | password = config['password'] 16 | ) 17 | 18 | conn = DBConnection() 19 | 20 | accepted_types = [m for m in config['accepted_types'] if config['accepted_types'][m] == True] 21 | 22 | source_type_mapping = { 23 | 'track': u'A new song was uploaded by {0}', 24 | 'track-repost': u'A song was reposted by {0}', 25 | 'comment': u'A new comment was given', 26 | 'favoriting': u'Someone liked a song' 27 | } 28 | 29 | def get_feeds(): 30 | result = [] 31 | 32 | feeds = conn.get_feeds(TYPE) 33 | 34 | count = 0 35 | 36 | for feed in feeds: 37 | if count >= config['max_count']: 38 | break 39 | 40 | result.append(Feeditem( 41 | content = json.loads(feed.content), 42 | type = feed.type, 43 | source = feed.source, 44 | time = feed.time, 45 | link = feed.link, 46 | )) 47 | 48 | count += 1 49 | 50 | return result 51 | 52 | def _load_feeds(): 53 | # print client.get('/me/activities').next_href 54 | 55 | try: 56 | elements = client.get('/me/activities').collection 57 | for element in elements: 58 | _type = element.type 59 | if _type not in accepted_types: 60 | continue 61 | 62 | content = None 63 | link = None 64 | 65 | source = source_type_mapping[_type] 66 | 67 | if _type == 'track' or _type == 'track-repost': 68 | content = json.dumps({ 69 | 'id': element.origin.id, 70 | 'username': element.origin.user['username'], 71 | 'tracktitle': element.origin.title, 72 | 'description': element.origin.description, 73 | 'songurl': element.origin.permalink_url, 74 | 'artworkurl': element.origin.artwork_url.replace('large', 't300x300'), 75 | 'waveformurl': element.origin.waveform_url, 76 | 'genre': element.origin.genre, 77 | 'duration': element.origin.duration, 78 | }) 79 | source = source.format(element.origin.user['username']) 80 | link = element.origin.permalink_url 81 | elif _type == 'comment': 82 | pass 83 | elif _type == 'favoriting': 84 | pass 85 | else: 86 | print 'Not accepted!' 87 | continue 88 | 89 | time = datetime.datetime.strptime(element.created_at, '%Y/%m/%d %H:%M:%S +%f') # e.g. 2016/02/17 15:03:31 +0000 90 | _save_element(content, source, time, link) 91 | except ConnectionError, e: 92 | return 93 | except Exception, e: 94 | return 95 | 96 | def _save_element(content, source, time, link): 97 | conn.insert_element( 98 | DBFeedItem( 99 | content, # content 100 | TYPE, # element type (soundcloud) 101 | source, # source (the type of the element from soundcloud) 102 | time, # time (as datetime) 103 | link, # link to source 104 | ) 105 | ) 106 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | importlib 2 | Flask 3 | html5lib 4 | feedparser 5 | Flask-Migrate 6 | Flask-Markdown 7 | soundcloud 8 | libkeepass 9 | praw 10 | github3.py==0.9.5 11 | -------------------------------------------------------------------------------- /static/images/centr_fav.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/static/images/centr_fav.png -------------------------------------------------------------------------------- /static/images/centr_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/static/images/centr_logo.png -------------------------------------------------------------------------------- /static/images/github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/static/images/github.png -------------------------------------------------------------------------------- /static/images/icon_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/static/images/icon_open.png -------------------------------------------------------------------------------- /static/images/reddit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/static/images/reddit.png -------------------------------------------------------------------------------- /static/images/rss.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/static/images/rss.png -------------------------------------------------------------------------------- /static/images/runtastic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/static/images/runtastic.png -------------------------------------------------------------------------------- /static/images/soundcloud.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/static/images/soundcloud.png -------------------------------------------------------------------------------- /static/js/main.js: -------------------------------------------------------------------------------- 1 | var header = document.getElementById("header"); 2 | 3 | function headerScroll() { 4 | if (window.pageYOffset > 0) { 5 | header.classList.add("header-fixed"); 6 | } else { 7 | header.classList.remove("header-fixed"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /static/js/waveform.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | var JSONP, Waveform, 3 | __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; 4 | 5 | window.Waveform = Waveform = (function() { 6 | 7 | Waveform.name = 'Waveform'; 8 | 9 | function Waveform(options) { 10 | this.redraw = __bind(this.redraw, this); 11 | this.container = options.container; 12 | this.canvas = options.canvas; 13 | this.data = options.data || []; 14 | this.outerColor = options.outerColor || "transparent"; 15 | this.innerColor = options.innerColor || "#000000"; 16 | this.interpolate = true; 17 | if (options.interpolate === false) { 18 | this.interpolate = false; 19 | } 20 | if (this.canvas == null) { 21 | if (this.container) { 22 | this.canvas = this.createCanvas(this.container, options.width || this.container.clientWidth, options.height || this.container.clientHeight); 23 | } else { 24 | throw "Either canvas or container option must be passed"; 25 | } 26 | } 27 | this.patchCanvasForIE(this.canvas); 28 | this.context = this.canvas.getContext("2d"); 29 | this.width = parseInt(this.context.canvas.width, 10); 30 | this.height = parseInt(this.context.canvas.height, 10); 31 | if (options.data) { 32 | this.update(options); 33 | } 34 | } 35 | 36 | Waveform.prototype.setData = function(data) { 37 | return this.data = data; 38 | }; 39 | 40 | Waveform.prototype.setDataInterpolated = function(data) { 41 | return this.setData(this.interpolateArray(data, this.width)); 42 | }; 43 | 44 | Waveform.prototype.setDataCropped = function(data) { 45 | return this.setData(this.expandArray(data, this.width)); 46 | }; 47 | 48 | Waveform.prototype.update = function(options) { 49 | if (options.interpolate != null) { 50 | this.interpolate = options.interpolate; 51 | } 52 | if (this.interpolate === false) { 53 | this.setDataCropped(options.data); 54 | } else { 55 | this.setDataInterpolated(options.data); 56 | } 57 | return this.redraw(); 58 | }; 59 | 60 | Waveform.prototype.redraw = function() { 61 | var d, i, middle, t, _i, _len, _ref, _results; 62 | this.clear(); 63 | if (typeof this.innerColor === "function") { 64 | this.context.fillStyle = this.innerColor(); 65 | } else { 66 | this.context.fillStyle = this.innerColor; 67 | } 68 | middle = this.height / 2; 69 | i = 0; 70 | _ref = this.data; 71 | _results = []; 72 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 73 | d = _ref[_i]; 74 | t = this.width / this.data.length; 75 | if (typeof this.innerColor === "function") { 76 | this.context.fillStyle = this.innerColor(i / this.width, d); 77 | } 78 | this.context.clearRect(t * i, middle - middle * d, t, middle * d * 2); 79 | this.context.fillRect(t * i, middle - middle * d, t, middle * d * 2); 80 | _results.push(i++); 81 | } 82 | return _results; 83 | }; 84 | 85 | Waveform.prototype.clear = function() { 86 | this.context.fillStyle = this.outerColor; 87 | this.context.clearRect(0, 0, this.width, this.height); 88 | return this.context.fillRect(0, 0, this.width, this.height); 89 | }; 90 | 91 | Waveform.prototype.patchCanvasForIE = function(canvas) { 92 | var oldGetContext; 93 | if (typeof window.G_vmlCanvasManager !== "undefined") { 94 | canvas = window.G_vmlCanvasManager.initElement(canvas); 95 | oldGetContext = canvas.getContext; 96 | return canvas.getContext = function(a) { 97 | var ctx; 98 | ctx = oldGetContext.apply(canvas, arguments); 99 | canvas.getContext = oldGetContext; 100 | return ctx; 101 | }; 102 | } 103 | }; 104 | 105 | Waveform.prototype.createCanvas = function(container, width, height) { 106 | var canvas; 107 | canvas = document.createElement("canvas"); 108 | container.appendChild(canvas); 109 | canvas.width = width; 110 | canvas.height = height; 111 | return canvas; 112 | }; 113 | 114 | Waveform.prototype.expandArray = function(data, limit, defaultValue) { 115 | var i, newData, _i, _ref; 116 | if (defaultValue == null) { 117 | defaultValue = 0.0; 118 | } 119 | newData = []; 120 | if (data.length > limit) { 121 | newData = data.slice(data.length - limit, data.length); 122 | } else { 123 | for (i = _i = 0, _ref = limit - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) { 124 | newData[i] = data[i] || defaultValue; 125 | } 126 | } 127 | return newData; 128 | }; 129 | 130 | Waveform.prototype.linearInterpolate = function(before, after, atPoint) { 131 | return before + (after - before) * atPoint; 132 | }; 133 | 134 | Waveform.prototype.interpolateArray = function(data, fitCount) { 135 | var after, atPoint, before, i, newData, springFactor, tmp; 136 | newData = new Array(); 137 | springFactor = new Number((data.length - 1) / (fitCount - 1)); 138 | newData[0] = data[0]; 139 | i = 1; 140 | while (i < fitCount - 1) { 141 | tmp = i * springFactor; 142 | before = new Number(Math.floor(tmp)).toFixed(); 143 | after = new Number(Math.ceil(tmp)).toFixed(); 144 | atPoint = tmp - before; 145 | newData[i] = this.linearInterpolate(data[before], data[after], atPoint); 146 | i++; 147 | } 148 | newData[fitCount - 1] = data[data.length - 1]; 149 | return newData; 150 | }; 151 | 152 | Waveform.prototype.optionsForSyncedStream = function(options) { 153 | var innerColorWasSet, that; 154 | if (options == null) { 155 | options = {}; 156 | } 157 | innerColorWasSet = false; 158 | that = this; 159 | return { 160 | whileplaying: this.redraw, 161 | whileloading: function() { 162 | var stream; 163 | if (!innerColorWasSet) { 164 | stream = this; 165 | that.innerColor = function(x, y) { 166 | if (x < stream.position / stream.durationEstimate) { 167 | return options.playedColor || "rgba(255, 102, 0, 0.8)"; 168 | } else if (x < stream.bytesLoaded / stream.bytesTotal) { 169 | return options.loadedColor || "rgba(0, 0, 0, 0.8)"; 170 | } else { 171 | return options.defaultColor || "rgba(0, 0, 0, 0.4)"; 172 | } 173 | }; 174 | innerColorWasSet = true; 175 | } 176 | return this.redraw; 177 | } 178 | }; 179 | }; 180 | 181 | Waveform.prototype.dataFromSoundCloudTrack = function(track) { 182 | var _this = this; 183 | return JSONP.get("http://www.waveformjs.org/w", { 184 | url: track.waveform_url 185 | }, function(data) { 186 | return _this.update({ 187 | data: data 188 | }); 189 | }); 190 | }; 191 | 192 | return Waveform; 193 | 194 | })(); 195 | 196 | JSONP = (function() { 197 | var config, counter, encode, head, jsonp, key, load, query, setDefaults, window; 198 | load = function(url) { 199 | var done, head, script; 200 | script = document.createElement("script"); 201 | done = false; 202 | script.src = url; 203 | script.async = true; 204 | script.onload = script.onreadystatechange = function() { 205 | if (!done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) { 206 | done = true; 207 | script.onload = script.onreadystatechange = null; 208 | if (script && script.parentNode) { 209 | return script.parentNode.removeChild(script); 210 | } 211 | } 212 | }; 213 | if (!head) { 214 | head = document.getElementsByTagName("head")[0]; 215 | } 216 | return head.appendChild(script); 217 | }; 218 | encode = function(str) { 219 | return encodeURIComponent(str); 220 | }; 221 | jsonp = function(url, params, callback, callbackName) { 222 | var key, query, uniqueName; 223 | query = ((url || "").indexOf("?") === -1 ? "?" : "&"); 224 | callbackName = callbackName || config["callbackName"] || "callback"; 225 | uniqueName = callbackName + "_json" + (++counter); 226 | params = params || {}; 227 | for (key in params) { 228 | if (params.hasOwnProperty(key)) { 229 | query += encode(key) + "=" + encode(params[key]) + "&"; 230 | } 231 | } 232 | window[uniqueName] = function(data) { 233 | callback(data); 234 | try { 235 | delete window[uniqueName]; 236 | } catch (_error) {} 237 | return window[uniqueName] = null; 238 | }; 239 | load(url + query + callbackName + "=" + uniqueName); 240 | return uniqueName; 241 | }; 242 | setDefaults = function(obj) { 243 | var config; 244 | return config = obj; 245 | }; 246 | counter = 0; 247 | head = void 0; 248 | query = void 0; 249 | key = void 0; 250 | window = this; 251 | config = {}; 252 | return { 253 | get: jsonp, 254 | init: setDefaults 255 | }; 256 | })(); 257 | 258 | }).call(this); 259 | -------------------------------------------------------------------------------- /static/styles/github.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ibiBgOR/centr/7b738e5c6b66ab478c5078f62392ff2039f59a3e/static/styles/github.css -------------------------------------------------------------------------------- /static/styles/layout.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Roboto); 2 | 3 | a { 4 | color: #000000; 5 | text-decoration: none; 6 | } 7 | 8 | body { 9 | margin: 0px; 10 | font-size: 16px; 11 | font-family: 'Roboto', sans-serif; 12 | display: flex; 13 | min-height: 100vh; 14 | flex-direction: column; 15 | } 16 | 17 | #header, #footer { 18 | min-width: calc(100% - 32px); 19 | padding: 16px; 20 | background-color: #607D8B; 21 | } 22 | 23 | #header { 24 | align-self: flex-start; 25 | color: #FFFFFF; 26 | font-size: 24px; 27 | font-weight: bold; 28 | } 29 | 30 | .header-fixed { 31 | position: fixed; 32 | z-index: 100; 33 | box-shadow: 0 0 4px rgba(0,0,0,.14),0 4px 8px rgba(0,0,0,.28); 34 | } 35 | 36 | #header-logo { 37 | width: 24px; 38 | padding: 0px 16px; 39 | } 40 | 41 | #content{ 42 | padding: 16px 0 16px; 43 | overflow: hidden; 44 | background-color: #EEEEEE; 45 | flex: 1; 46 | } 47 | 48 | .datedevider { 49 | width: calc(750px - 2 * 16px); /* 2 * 16 is the padding. Otherwise this padding won't have any effect. */ 50 | display: flex; 51 | padding: 16px; 52 | margin: 0 auto; 53 | font-size: 14px; 54 | color: #000000; 55 | opacity: 0.54; 56 | } 57 | 58 | .card { 59 | width: 750px; 60 | height: auto; 61 | display: flex; 62 | flex-direction: column; 63 | margin: 0 auto 10px auto; 64 | font-size: 14px; 65 | border-radius: 2px; 66 | background-color: #FFFFFF; 67 | box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); 68 | } 69 | 70 | .cardheader { 71 | height: 40px; 72 | padding: 16px; 73 | } 74 | 75 | .cardicon { 76 | width: 40px; 77 | height: 40px; 78 | float: left; 79 | margin-right: 16px; 80 | border-radius: 20px; 81 | } 82 | 83 | .cardtitle { 84 | float: left; 85 | padding: 4px 0 4px 0; 86 | } 87 | 88 | .cardlink { 89 | padding: 8px; 90 | float: right; 91 | } 92 | 93 | .cardsource { 94 | opacity: 0.87; 95 | } 96 | 97 | .cardtime { 98 | opacity: 0.54; 99 | } 100 | 101 | .cardcontent { 102 | padding: 0 16px; 103 | margin-bottom: 16px; 104 | } 105 | 106 | .cardaction { 107 | min-width: 88px; 108 | height: 36px; 109 | float: right; 110 | padding: 0 6px 0 6px; 111 | margin: 6px 8px 6px 0px; 112 | min-width: 88px; 113 | border-radius: 3px; 114 | background-color: transparent; 115 | font-size: 14px; 116 | text-align: center; 117 | text-transform: uppercase; 118 | text-decoration:none; 119 | border: none; 120 | outline: none; 121 | } 122 | 123 | .cardaction:hover { 124 | background-color: rgba(158, 158, 158, 0.2); 125 | } 126 | 127 | #footer { 128 | align-self: flex-start; 129 | } 130 | -------------------------------------------------------------------------------- /static/styles/reddit.css: -------------------------------------------------------------------------------- 1 | blockquote { 2 | border-left: 2px solid #c5c1ad; 3 | padding: 0 8px; 4 | margin-left: 5px; 5 | } 6 | 7 | .reddit { 8 | 9 | } 10 | 11 | .reddit .thumbnail { 12 | float: left; 13 | width: 30%; 14 | height: auto; 15 | margin-right: 16px; 16 | border-radius: 2px; 17 | } 18 | -------------------------------------------------------------------------------- /static/styles/rss.css: -------------------------------------------------------------------------------- 1 | .rss { 2 | padding-right: 10px; 3 | width: 100%; 4 | } 5 | 6 | .rss img { 7 | max-width: 100%; 8 | display: block; 9 | margin: 0 auto; 10 | } 11 | -------------------------------------------------------------------------------- /static/styles/soundcloud.css: -------------------------------------------------------------------------------- 1 | .soundcloud { 2 | display: flex; 3 | flex-direction: row; 4 | } 5 | 6 | .artwork { 7 | align-self: center; 8 | width: 142px !important; 9 | height: 142px !important; 10 | margin-right: 16px; 11 | } 12 | 13 | .right-pannel { 14 | display: flex; 15 | flex-direction: column; 16 | } 17 | 18 | .user-track { 19 | display: flex; 20 | flex-direction: column; 21 | } 22 | 23 | .user-track-item { 24 | margin-bottom: 2px; 25 | } 26 | 27 | .waveform { 28 | width: 558px; 29 | height: 100px; 30 | } 31 | -------------------------------------------------------------------------------- /templates/cards/github.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | -------------------------------------------------------------------------------- /templates/cards/reddit.html: -------------------------------------------------------------------------------- 1 |
2 | {% if item.content.thumbnail %} 3 | thumbnail 4 | {% endif %} 5 | Post: {{ item.content.post_name }}
6 | 7 |
8 | -------------------------------------------------------------------------------- /templates/cards/rss.html: -------------------------------------------------------------------------------- 1 |
2 | {{ item.content | safe }} 3 |
4 | -------------------------------------------------------------------------------- /templates/cards/runtastic.html: -------------------------------------------------------------------------------- 1 |
2 | {{ item.content }} 3 |
4 | -------------------------------------------------------------------------------- /templates/cards/soundcloud.html: -------------------------------------------------------------------------------- 1 |
2 | Artwork 3 |
4 |
5 | {{ item.content.username }} 6 | {{ item.content.tracktitle }} 7 |
8 |
9 | 10 |
11 |
12 |
13 | 14 | 33 | -------------------------------------------------------------------------------- /templates/dashboard.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | centr 5 | 6 | 7 | 8 | {% for item in addonitems %} 9 | 10 | {% endfor %} 11 | 12 | 13 | {% include 'header.html' %} 14 | 15 |
16 | {% for item in feeditems %} 17 | {% if item.time.year < date.year or item.time.month < date.month or item.time.day < date.day %} 18 | {% set date = item.time %} 19 | {{ date | datetime }} 20 | {% endif %} 21 |
22 |
23 | {{ 24 |
25 | {{ item.source }}
26 | {{ item.time }} 27 |
28 | {% if extended and item.link %} 29 | 30 | Open Website 31 | 32 | {% endif %} 33 |
34 | {% if item.content %} 35 |
36 | {% include 'cards/' + item.type + '.html' ignore missing %} 37 |
38 | {% endif %} 39 |
40 | {% endfor %} 41 |
42 | {% include 'footer.html' %} 43 | 44 | 45 | -------------------------------------------------------------------------------- /templates/footer.html: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /templates/header.html: -------------------------------------------------------------------------------- 1 | 7 | --------------------------------------------------------------------------------