aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/.hgsub1
-rwxr-xr-xsource/COPYING674
-rw-r--r--source/README84
-rw-r--r--source/cfg/cherrypy.cfg24
-rwxr-xr-xsource/cfg/pyAggr3g470r.cfg-sample15
-rwxr-xr-xsource/css/style.css374
-rw-r--r--source/epub/__init__.py1
-rw-r--r--source/epub/epub.py343
-rw-r--r--source/epub/ez_epub.py36
-rw-r--r--source/epub/templates/container.xml6
-rw-r--r--source/epub/templates/content.opf34
-rw-r--r--source/epub/templates/ez-section.html17
-rw-r--r--source/epub/templates/image.html16
-rw-r--r--source/epub/templates/title-page.html22
-rw-r--r--source/epub/templates/toc.html32
-rw-r--r--source/epub/templates/toc.ncx28
-rw-r--r--source/export.py190
-rwxr-xr-xsource/feedgetter.py167
-rwxr-xr-xsource/img/blogmarks.pngbin0 -> 195 bytes
-rw-r--r--source/img/check-news.pngbin0 -> 1383 bytes
-rw-r--r--source/img/cross.pngbin0 -> 655 bytes
-rw-r--r--source/img/diaspora.pngbin0 -> 1179 bytes
-rwxr-xr-xsource/img/digg.pngbin0 -> 358 bytes
-rw-r--r--source/img/email-follow.pngbin0 -> 4056 bytes
-rw-r--r--source/img/favicon.pngbin0 -> 6879 bytes
-rwxr-xr-xsource/img/feed-icon-28x28.pngbin0 -> 1737 bytes
-rw-r--r--source/img/following-article.pngbin0 -> 989 bytes
-rw-r--r--source/img/hacker-news.pngbin0 -> 265 bytes
-rw-r--r--source/img/heart-32x32.pngbin0 -> 2084 bytes
-rw-r--r--source/img/heart.pngbin0 -> 634 bytes
-rw-r--r--source/img/heart_open.pngbin0 -> 687 bytes
-rw-r--r--source/img/history.pngbin0 -> 3257 bytes
-rw-r--r--source/img/identica.pngbin0 -> 459 bytes
-rw-r--r--source/img/management.pngbin0 -> 2916 bytes
-rw-r--r--source/img/mark-as-read.pngbin0 -> 1762 bytes
-rw-r--r--source/img/pinboard.pngbin0 -> 597 bytes
-rw-r--r--source/img/previous-article.pngbin0 -> 997 bytes
-rwxr-xr-xsource/img/reddit.pngbin0 -> 525 bytes
-rwxr-xr-xsource/img/scoopeo.pngbin0 -> 295 bytes
-rw-r--r--source/img/tuxrss.pngbin0 -> 6879 bytes
-rw-r--r--source/img/unread.pngbin0 -> 1580 bytes
-rw-r--r--source/mongodb.py253
-rwxr-xr-xsource/pyAggr3g470r130
-rwxr-xr-xsource/pyAggr3g470r.py1271
-rw-r--r--source/sqlite2mongo.py78
-rwxr-xr-xsource/utils.py351
-rwxr-xr-xsource/var/feed.lst37
47 files changed, 4184 insertions, 0 deletions
diff --git a/source/.hgsub b/source/.hgsub
new file mode 100644
index 00000000..bc339e87
--- /dev/null
+++ b/source/.hgsub
@@ -0,0 +1 @@
+qrcode = http://hg.cedricbonhomme.org/qrcode/
diff --git a/source/COPYING b/source/COPYING
new file mode 100755
index 00000000..20d40b6b
--- /dev/null
+++ b/source/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ <program> Copyright (C) <year> <name of author>
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>. \ No newline at end of file
diff --git a/source/README b/source/README
new file mode 100644
index 00000000..a2737f76
--- /dev/null
+++ b/source/README
@@ -0,0 +1,84 @@
+.. -*-restructuredtext-*-
+
+============
+pyAggr3g470r
+============
+
+.. Use headers in this order #=~-_
+
+:toc: yes
+:symrefs: yes
+:sortrefs: yes
+:compact: yes
+:subcompact: no
+:rfcedstyle: no
+:comments: no
+:inline: yes
+:private: yes
+
+:author: Cédric Bonhomme
+:contact: http://cedricbonhomme.org/
+
+
+Presentation
+------------
+pyAggr3g470r_ is a multi-threaded news aggregator with a web interface
+based on CherryPy_. Articles are stored in a MongoDB_ base.
+
+
+
+Features
+------------
+* articles are stored in a MongoDB_ database;
+* find an article with history;
+* e-mail notification;
+* export articles to HTML, EPUB, PDF or raw text;
+* mark or unmark articles as favorites;
+* share articles with Diaspora, Google Buzz, Pinboard, delicious, Identi.ca, Digg, reddit, Scoopeo, Blogmarks and Twitter;
+* generation of QR code with the content or URL of an article. So you can read an article later on your smartphone (or share with friends).
+
+
+
+Requierements
+-------------
+Software required
+~~~~~~~~~~~~~~~~~
+* Python_ 2.7.*;
+* MongoDB_ and PyMongo_;
+* feedparser_;
+* CherryPy_ (version 3 and up);
+* BeautifulSoup_.
+
+
+Optional module
+~~~~~~~~~~~~~~~
+These modules are not required but enables more features:
+* lxml and Genshi;
+* Python Imaging Library for the generation of QR codes.
+
+
+If you want to install these modules:
+
+ sudo aptitude install python-lxml python-genshi
+
+
+Donnation
+---------
+If you wish and if you like pyAggr3g470r, you can donate via bitcoin. My bitcoin address: 1GVmhR9fbBeEh7rP1qNq76jWArDdDQ3otZ
+Thank you!
+
+
+
+License
+------------
+pyAggr3g470r_ is under GPLv3_ license.
+
+
+.. _Python: http://python.org/
+.. _pyAggr3g470r: https://bitbucket.org/cedricbonhomme/pyaggr3g470r/
+.. _feedparser: http://feedparser.org/
+.. _MongoDB: http://www.mongodb.org/
+.. _PyMongo: https://github.com/mongodb/mongo-python-driver
+.. _CherryPy: http://cherrypy.org/
+.. _BeautifulSoup: http://www.crummy.com/software/BeautifulSoup/
+.. _GPLv3: http://www.gnu.org/licenses/gpl-3.0.txt
diff --git a/source/cfg/cherrypy.cfg b/source/cfg/cherrypy.cfg
new file mode 100644
index 00000000..a419504d
--- /dev/null
+++ b/source/cfg/cherrypy.cfg
@@ -0,0 +1,24 @@
+[global]
+log.error_file = "var/error.log"
+log.access_file = "var/access.log"
+server.environment = "production"
+engine.autoreload_on = True
+engine.autoreload_frequency = 5
+engine.timeout_monitor.on = False
+
+[/]
+tools.staticdir.root = os.getcwd()
+tools.staticdir.on = True
+tools.staticdir.dir = "."
+tools.encode.on = True
+tools.encode.encoding = "utf8"
+
+[/css]
+tools.staticdir.on = True
+tools.staticdir.dir = "css"
+tools.staticdir.match = "(?i)^.+\.css$"
+
+[/images]
+tools.staticdir.on = True
+tools.staticdir.dir = "img"
+tools.staticdir.match = "(?i)^.+\.png$" \ No newline at end of file
diff --git a/source/cfg/pyAggr3g470r.cfg-sample b/source/cfg/pyAggr3g470r.cfg-sample
new file mode 100755
index 00000000..95db75c5
--- /dev/null
+++ b/source/cfg/pyAggr3g470r.cfg-sample
@@ -0,0 +1,15 @@
+[global]
+max_nb_articles = 50
+[MongoDB]
+address = 127.0.0.1
+port = 27017
+user = username
+password = pwd
+[mail]
+mail_from = pyAggr3g470r@no-reply.com
+mail_to = address_of_the_recipient@example.com
+smtp = smtp.example.com
+username = your_mail_address@example.com
+password = your_password
+[misc]
+diaspora_pod = joindiaspora.com
diff --git a/source/css/style.css b/source/css/style.css
new file mode 100755
index 00000000..5f9574e7
--- /dev/null
+++ b/source/css/style.css
@@ -0,0 +1,374 @@
+html, body {
+ margin: 0;
+ padding: 0;
+ width: 100%;
+ height: 100%;
+ overflow-x: hidden;
+ background-color: white;
+ color: black;
+}
+
+body {
+ text-align: justify;
+ font: 400 0.85em Cambria, Georgia, "Trebuchet MS", Verdana, sans-serif;
+}
+
+code, pre {
+ font: 400 0.85em Cambria, Georgia, "Trebuchet MS", Verdana, sans-serif, Fixed;
+ white-space:pre-wrap;
+}
+
+img {
+ border: 0px;
+}
+
+h1 {
+ font-size: 100%;
+ margin: 0em 0em;
+ padding: 0px;
+}
+
+h2 {
+ margin: 0.5em 0em;
+ padding: 0px;
+ font-style: normal;
+ font-variant: normal;
+ font-weight: bold;
+ font-size: 100%;
+ letter-spacing: 0em;
+ text-align: right;
+}
+
+h3 {
+ margin: 0em 0em 0.5em 0em;
+ font-size: 100%;
+ font-weight: bold;
+ text-align: left;
+}
+
+h1 a, h2 a, h3 a {
+ text-decoration: none;
+}
+
+h2 + h3 {
+ margin-top: 0.5em;
+}
+
+table {
+ margin-left: 2em;
+ margin-bottom: 1em;
+ border-collapse: collapse;
+ text-align: left;
+}
+
+th, td {
+ padding-right: 1em;
+ text-align: left;
+}
+
+th {
+ vertical-align: bottom;
+ border-bottom: 1px solid black;
+ text-align: left;
+}
+
+td {
+ vertical-align: top;
+ padding-top: 5px;
+ text-align: left;
+}
+
+table.border td, table.border th {
+ border: 1px solid black;
+}
+
+p {
+ margin: 0.5em 0em;
+}
+
+ol.lower {
+ list-style-type: lower-alpha;
+}
+
+ol.upper {
+ list-style-type: upper-alpha;
+}
+
+ol.roman {
+ list-style-type: lower-roman;
+}
+
+ul {
+ margin: 0em 0em 0.5em 0.5em;
+ padding: 0em;
+}
+
+li {
+ margin: 0em 0em 0em 0.5em;
+ padding: 0em;
+}
+
+a:link, a:visited {
+ color: #003399;
+ text-decoration:none
+}
+
+a:hover {
+ color: blue;
+}
+
+dt {
+ margin: 0.5em 0em 0em 0em;
+ padding: 0em;
+ font-weight: bold;
+}
+
+dd {
+ margin: 0em;
+}
+
+hr {
+ color: white;
+ border-top: dotted black;
+ border-width: 1px 0px 0px 0px;
+ margin: 1em 0em;
+}
+
+
+#heading {
+ position: absolute;
+ left: 0px;
+ top: 0px;
+ width: 100%;
+ z-index: 1;
+}
+
+/* Navigation bars */
+.nav_container { position:fixed; top:160px; right:60px; margin:0px; padding:0px; white-space:nowrap; z-index:11; clear:both;}
+.nav_container.horizontal { position:absolute; white-space:normal; z-index:25; width:670px; }
+.nav_container.horizontal div { float:right; padding-right:10px; }
+
+#nav {
+ position: absolute;
+ top: 0px;
+ right: 0px;
+ z-index: 2;
+}
+
+#heading, #nav, #nav ul {
+ margin: 0;
+ height: 1.8em;
+}
+
+#heading, #nav ul, #nav li {
+ background: #EEEEEE;
+ color: inherit;
+ border-bottom: 0px solid black;
+}
+
+#heading h1 {
+ margin: 0;
+ padding: 0.4em 0 0.4em 2em;
+ white-space: nowrap;
+}
+
+#nav ul {
+ display: block;
+ margin: 0 3em 0 0;
+ border-right: 0px solid #000000;
+}
+
+#nav li {
+ margin: 0em;
+ padding: 0.4em 1em 0.2em 1em;
+ display: block;
+ float: left;
+ border-left: 0px solid #000000;
+}
+
+pre {
+ margin-left: 2em;
+}
+
+.right {
+ clear: right;
+ float: right;
+ text-align: right;
+ margin: 0em 2em 0em 2em;
+ max-width: 36%;
+}
+
+img.right {
+ width: auto;
+}
+
+.inner .right {
+ margin-right: 0em;
+}
+
+.right blockquote {
+ float: right;
+ position: relative;
+ clear: both;
+ padding-top: 1em;
+ padding-bottom: 0em;
+ margin-bottom: 0em;
+ font-style: italic;
+ width: 100%;
+ margin-right: 0em;
+}
+
+blockquote.right {
+ width: 50%;
+ margin-left: 50%;
+ margin-right: 0em;
+}
+
+/* Footer (W3C logos) */
+
+#w3c {
+ text-align: right;
+ padding: 0em 2em 0em 2em;
+ clear: both;
+}
+
+#w3c img {
+ padding-left: 10px;
+ padding-top: 1em;
+}
+
+/* Classes */
+
+.clear {
+ font-size: 1px;
+ line-height: 1px;
+ height: 0px;
+ clear: both;
+}
+
+.invisible {
+ display: none;
+}
+
+.inner {
+ margin-top: 3em;
+ padding: 0em 2em 0em 2em;
+ clear: both;
+}
+
+.innerlogo {
+ margin-top: 0em;
+ padding: 0em 2em 0em 2em;
+ clear: both;
+}
+
+.left {
+ float: left;
+ position: absolute;
+
+}
+
+.tex {
+ position: relative; top: 0.2em;
+ margin-left: -0.2em;
+ margin-right: -0.1em;
+}
+
+/* Photo album */
+
+#album {
+ margin: 0 auto;
+ padding: 3em 2em 0em 2em;
+}
+
+#thumbs {
+ background: white;
+ position: absolute;
+ left: 2em;
+ right: 2em;
+ margin-top: -100px;
+ padding-bottom: 0.5em;
+ overflow: auto;
+}
+
+#thumbs table {
+ margin: 0 auto;
+ position: relative;
+ max-width: 100%;
+ border-collapse: collapse;
+ border: 0px;
+}
+
+#pageselectors {
+ margin-top: 1em;
+ text-align: center;
+ padding-bottom: 100px;
+ margin-bottom: 0.5em;
+}
+
+#thumbs img, #photo img {
+ display: block;
+ margin: 0 auto;
+}
+
+#thumbs td {
+ width: 8em;
+ min-width: 100px;
+ text-align: center;
+ padding: 0.5em 0.5em 0em 0em;
+ border: 0px;
+ margin: 0px;
+}
+
+#photo {
+ text-align: center;
+}
+
+#thumbs img {
+ opacity: 0.99;
+ -moz-opacity: 0.99;
+}
+
+#thumbs img:hover {
+ opacity: 0.7;
+ -moz-opacity: 0.7;
+}
+
+#photo img {
+ max-width: 100%;
+ min-height: 300px;
+ max-height: 300px;
+ overflow: scroll;
+ margin-top: 0.5em;
+}
+
+/* CSS ToolTips */
+ .tooltip {
+ color: #FFF;
+ outline: none;
+ text-decoration: none;
+ position: relative;
+ }
+
+ .tooltip span {
+ color: #FFF;
+ margin-left: -999em;
+ position: absolute;
+ }
+
+ .tooltip:hover span {
+ border-radius: 5px 5px; -moz-border-radius: 5px; -webkit-border-radius: 5px;
+ box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 5px 5px rgba(0, 0, 0, 0.1); -moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);
+ font-family: Calibri, Tahoma, Geneva, sans-serif;
+ position: absolute; left: 1em; top: 2em; z-index: 99;
+ margin-left: 0; width: 250px;
+ }
+ .classic {
+ padding: 0.8em 1em;
+ background: rgba(0, 0, 0, 0.85);
+ border: 5px 5px;
+ }
+
+ * html a:hover {
+ background: transparent;
+ } \ No newline at end of file
diff --git a/source/epub/__init__.py b/source/epub/__init__.py
new file mode 100644
index 00000000..8d1c8b69
--- /dev/null
+++ b/source/epub/__init__.py
@@ -0,0 +1 @@
+
diff --git a/source/epub/epub.py b/source/epub/epub.py
new file mode 100644
index 00000000..2c01b54a
--- /dev/null
+++ b/source/epub/epub.py
@@ -0,0 +1,343 @@
+#! /usr/local/bin/python
+#-*- coding: utf-8 -*-
+
+import itertools
+import mimetypes
+import os
+import shutil
+import subprocess
+import uuid
+import zipfile
+from genshi.template import TemplateLoader
+from lxml import etree
+
+class TocMapNode:
+ def __init__(self):
+ self.playOrder = 0
+ self.title = ''
+ self.href = ''
+ self.children = []
+ self.depth = 0
+
+ def assignPlayOrder(self):
+ nextPlayOrder = [0]
+ self.__assignPlayOrder(nextPlayOrder)
+
+ def __assignPlayOrder(self, nextPlayOrder):
+ self.playOrder = nextPlayOrder[0]
+ nextPlayOrder[0] = self.playOrder + 1
+ for child in self.children:
+ child.__assignPlayOrder(nextPlayOrder)
+
+class EpubItem:
+ def __init__(self):
+ self.id = ''
+ self.srcPath = ''
+ self.destPath = ''
+ self.mimeType = ''
+ self.html = ''
+
+class EpubBook:
+ def __init__(self):
+ self.loader = TemplateLoader('./epub/templates')
+
+ self.rootDir = ''
+ self.UUID = uuid.uuid1()
+
+ self.lang = 'en-US'
+ self.title = ''
+ self.creators = []
+ self.metaInfo = []
+
+ self.imageItems = {}
+ self.htmlItems = {}
+ self.cssItems = {}
+
+ self.coverImage = None
+ self.titlePage = None
+ self.tocPage = None
+
+ self.spine = []
+ self.guide = {}
+ self.tocMapRoot = TocMapNode()
+ self.lastNodeAtDepth = {0 : self.tocMapRoot}
+
+ def setTitle(self, title):
+ self.title = title
+
+ def setLang(self, lang):
+ self.lang = lang
+
+ def addCreator(self, name, role = 'aut'):
+ self.creators.append((name, role))
+
+ def addMeta(self, metaName, metaValue, **metaAttrs):
+ self.metaInfo.append((metaName, metaValue, metaAttrs))
+
+ def getMetaTags(self):
+ l = []
+ for metaName, metaValue, metaAttr in self.metaInfo:
+ beginTag = '<dc:%s' % metaName
+ if metaAttr:
+ for attrName, attrValue in metaAttr.iteritems():
+ beginTag += ' opf:%s="%s"' % (attrName, attrValue)
+ beginTag += '>'
+ endTag = '</dc:%s>' % metaName
+ l.append((beginTag, metaValue, endTag))
+ return l
+
+ def getImageItems(self):
+ return sorted(self.imageItems.values(), key = lambda x : x.id)
+
+ def getHtmlItems(self):
+ return sorted(self.htmlItems.values(), key = lambda x : x.id)
+
+ def getCssItems(self):
+ return sorted(self.cssItems.values(), key = lambda x : x.id)
+
+ def getAllItems(self):
+ return sorted(itertools.chain(self.imageItems.values(), self.htmlItems.values(), self.cssItems.values()), key = lambda x : x.id)
+
+ def addImage(self, srcPath, destPath):
+ item = EpubItem()
+ item.id = 'image_%d' % (len(self.imageItems) + 1)
+ item.srcPath = srcPath
+ item.destPath = destPath
+ item.mimeType = mimetypes.guess_type(destPath)[0]
+ assert item.destPath not in self.imageItems
+ self.imageItems[destPath] = item
+ return item
+
+ def addHtmlForImage(self, imageItem):
+ tmpl = self.loader.load('image.html')
+ stream = tmpl.generate(book = self, item = imageItem)
+ html = stream.render('xhtml', doctype = 'xhtml11', drop_xml_decl = False)
+ return self.addHtml('', '%s.html' % imageItem.destPath, html)
+
+ def addHtml(self, srcPath, destPath, html):
+ item = EpubItem()
+ item.id = 'html_%d' % (len(self.htmlItems) + 1)
+ item.srcPath = srcPath
+ item.destPath = destPath
+ item.html = html
+ item.mimeType = 'application/xhtml+xml'
+ assert item.destPath not in self.htmlItems
+ self.htmlItems[item.destPath] = item
+ return item
+
+ def addCss(self, srcPath, destPath):
+ item = EpubItem()
+ item.id = 'css_%d' % (len(self.cssItems) + 1)
+ item.srcPath = srcPath
+ item.destPath = destPath
+ item.mimeType = 'text/css'
+ assert item.destPath not in self.cssItems
+ self.cssItems[item.destPath] = item
+ return item
+
+ def addCover(self, srcPath):
+ assert not self.coverImage
+ _, ext = os.path.splitext(srcPath)
+ destPath = 'cover%s' % ext
+ self.coverImage = self.addImage(srcPath, destPath)
+ #coverPage = self.addHtmlForImage(self.coverImage)
+ #self.addSpineItem(coverPage, False, -300)
+ #self.addGuideItem(coverPage.destPath, 'Cover', 'cover')
+
+ def __makeTitlePage(self):
+ assert self.titlePage
+ if self.titlePage.html:
+ return
+ tmpl = self.loader.load('title-page.html')
+ stream = tmpl.generate(book = self)
+ self.titlePage.html = stream.render('xhtml', doctype = 'xhtml11', drop_xml_decl = False)
+
+ def addTitlePage(self, html = ''):
+ assert not self.titlePage
+ self.titlePage = self.addHtml('', 'title-page.html', html)
+ self.addSpineItem(self.titlePage, True, -200)
+ self.addGuideItem('title-page.html', 'Title Page', 'title-page')
+
+ def __makeTocPage(self):
+ assert self.tocPage
+ tmpl = self.loader.load('toc.html')
+ stream = tmpl.generate(book = self)
+ self.tocPage.html = stream.render('xhtml', doctype = 'xhtml11', drop_xml_decl = False)
+
+ def addTocPage(self):
+ assert not self.tocPage
+ self.tocPage = self.addHtml('', 'toc.html', '')
+ self.addSpineItem(self.tocPage, False, -100)
+ self.addGuideItem('toc.html', 'Table of Contents', 'toc')
+
+ def getSpine(self):
+ return sorted(self.spine)
+
+ def addSpineItem(self, item, linear = True, order = None):
+ assert item.destPath in self.htmlItems
+ if order == None:
+ order = (max(order for order, _, _ in self.spine) if self.spine else 0) + 1
+ self.spine.append((order, item, linear))
+
+ def getGuide(self):
+ return sorted(self.guide.values(), key = lambda x : x[2])
+
+ def addGuideItem(self, href, title, type):
+ assert type not in self.guide
+ self.guide[type] = (href, title, type)
+
+ def getTocMapRoot(self):
+ return self.tocMapRoot
+
+ def getTocMapHeight(self):
+ return max(self.lastNodeAtDepth.keys())
+
+ def addTocMapNode(self, href, title, depth = None, parent = None):
+ node = TocMapNode()
+ node.href = href
+ node.title = title
+ if parent == None:
+ if depth == None:
+ parent = self.tocMapRoot
+ else:
+ parent = self.lastNodeAtDepth[depth - 1]
+ parent.children.append(node)
+ node.depth = parent.depth + 1
+ self.lastNodeAtDepth[node.depth] = node
+ return node
+
+ def makeDirs(self):
+ try:
+ os.makedirs(os.path.join(self.rootDir, 'META-INF'))
+ except OSError:
+ pass
+ try:
+ os.makedirs(os.path.join(self.rootDir, 'OEBPS'))
+ except OSError:
+ pass
+
+ def __writeContainerXML(self):
+ fout = open(os.path.join(self.rootDir, 'META-INF', 'container.xml'), 'w')
+ tmpl = self.loader.load('container.xml')
+ stream = tmpl.generate()
+ fout.write(stream.render('xml'))
+ fout.close()
+
+ def __writeTocNCX(self):
+ self.tocMapRoot.assignPlayOrder()
+ fout = open(os.path.join(self.rootDir, 'OEBPS', 'toc.ncx'), 'w')
+ tmpl = self.loader.load('toc.ncx')
+ stream = tmpl.generate(book = self)
+ fout.write(stream.render('xml'))
+ fout.close()
+
+ def __writeContentOPF(self):
+ fout = open(os.path.join(self.rootDir, 'OEBPS', 'content.opf'), 'w')
+ tmpl = self.loader.load('content.opf')
+ stream = tmpl.generate(book = self)
+ fout.write(stream.render('xml'))
+ fout.close()
+
+ def __writeItems(self):
+ for item in self.getAllItems():
+ #print item.id, item.destPath
+ if item.html:
+ fout = open(os.path.join(self.rootDir, 'OEBPS', item.destPath), 'w')
+ fout.write(item.html)
+ fout.close()
+ else:
+ shutil.copyfile(item.srcPath, os.path.join(self.rootDir, 'OEBPS', item.destPath))
+
+
+ def __writeMimeType(self):
+ fout = open(os.path.join(self.rootDir, 'mimetype'), 'w')
+ fout.write('application/epub+zip')
+ fout.close()
+
+ @staticmethod
+ def __listManifestItems(contentOPFPath):
+ tree = etree.parse(contentOPFPath)
+ return tree.xpath("//opf:manifest/opf:item/@href", namespaces = {'opf': 'http://www.idpf.org/2007/opf'})
+
+ @staticmethod
+ def createArchive(rootDir, outputPath):
+ fout = zipfile.ZipFile(outputPath, 'w')
+ cwd = os.getcwd()
+ os.chdir(rootDir)
+ fout.write('mimetype', compress_type = zipfile.ZIP_STORED)
+ fileList = []
+ fileList.append(os.path.join('META-INF', 'container.xml'))
+ fileList.append(os.path.join('OEBPS', 'content.opf'))
+ for itemPath in EpubBook.__listManifestItems(os.path.join('OEBPS', 'content.opf')):
+ fileList.append(os.path.join('OEBPS', itemPath))
+ for filePath in fileList:
+ fout.write(filePath, compress_type = zipfile.ZIP_DEFLATED)
+ fout.close()
+ os.chdir(cwd)
+
+ def createBook(self, rootDir):
+ if self.titlePage:
+ self.__makeTitlePage()
+ if self.tocPage:
+ self.__makeTocPage()
+ self.rootDir = rootDir
+ self.makeDirs()
+ self.__writeMimeType()
+ self.__writeItems()
+ self.__writeContainerXML()
+ self.__writeContentOPF()
+ self.__writeTocNCX()
+
+def test():
+ def getMinimalHtml(text):
+ return """<!DOCTYPE html PUBLIC "-//W3C//DTD XHtml 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head><title>%s</title></head>
+<body><p>%s</p></body>
+</html>
+""" % (text, text)
+
+ book = EpubBook()
+ book.setTitle('Most Wanted Tips for Aspiring Young Pirates')
+ book.addCreator('Monkey D Luffy')
+ book.addCreator('Guybrush Threepwood')
+ book.addMeta('contributor', 'Smalltalk80', role = 'bkp')
+ book.addMeta('date', '2010', event = 'publication')
+
+ book.addTitlePage()
+ book.addTocPage()
+ book.addCover(r'D:\epub\blank.png')
+
+ book.addCss(r'main.css', 'main.css')
+
+ n1 = book.addHtml('', '1.html', getMinimalHtml('Chapter 1'))
+ n11 = book.addHtml('', '2.html', getMinimalHtml('Section 1.1'))
+ n111 = book.addHtml('', '3.html', getMinimalHtml('Subsection 1.1.1'))
+ n12 = book.addHtml('', '4.html', getMinimalHtml('Section 1.2'))
+ n2 = book.addHtml('', '5.html', getMinimalHtml('Chapter 2'))
+
+ book.addSpineItem(n1)
+ book.addSpineItem(n11)
+ book.addSpineItem(n111)
+ book.addSpineItem(n12)
+ book.addSpineItem(n2)
+
+ # You can use both forms to add TOC map
+ #t1 = book.addTocMapNode(n1.destPath, '1')
+ #t11 = book.addTocMapNode(n11.destPath, '1.1', parent = t1)
+ #t111 = book.addTocMapNode(n111.destPath, '1.1.1', parent = t11)
+ #t12 = book.addTocMapNode(n12.destPath, '1.2', parent = t1)
+ #t2 = book.addTocMapNode(n2.destPath, '2')
+
+ book.addTocMapNode(n1.destPath, '1')
+ book.addTocMapNode(n11.destPath, '1.1', 2)
+ book.addTocMapNode(n111.destPath, '1.1.1', 3)
+ book.addTocMapNode(n12.destPath, '1.2', 2)
+ book.addTocMapNode(n2.destPath, '2')
+
+ rootDir = r'd:\epub\test'
+ book.createBook(rootDir)
+ EpubBook.createArchive(rootDir, rootDir + '.epub')
+
+if __name__ == '__main__':
+ test() \ No newline at end of file
diff --git a/source/epub/ez_epub.py b/source/epub/ez_epub.py
new file mode 100644
index 00000000..ecfd4f5a
--- /dev/null
+++ b/source/epub/ez_epub.py
@@ -0,0 +1,36 @@
+#! /usr/local/bin/python
+#-*- coding: utf-8 -*-
+
+import epub
+from genshi.template import TemplateLoader
+
+class Section:
+ def __init__(self):
+ self.title = ''
+ self.paragraphs = []
+ self.tocDepth = 1
+
+def makeBook(title, authors, sections, outputDir, lang='en-US', cover=None):
+ book = epub.EpubBook()
+ book.setLang(lang)
+ book.setTitle(title)
+ for author in authors:
+ book.addCreator(author)
+ #book.addTitlePage()
+ #book.addTocPage()
+ #if cover:
+ #book.addCover(cover)
+
+ loader = TemplateLoader('./epub/templates')
+ tmpl = loader.load('ez-section.html')
+
+ for i, section in enumerate(sections):
+ stream = tmpl.generate(section = section)
+ html = stream.render('xhtml', doctype='xhtml11', drop_xml_decl=False)
+ item = book.addHtml('', 's%d.html' % (i + 1), html)
+ book.addSpineItem(item)
+ book.addTocMapNode(item.destPath, section.title, section.tocDepth)
+
+ outputFile = outputDir + 'article.epub'
+ book.createBook(outputDir)
+ book.createArchive(outputDir, outputFile) \ No newline at end of file
diff --git a/source/epub/templates/container.xml b/source/epub/templates/container.xml
new file mode 100644
index 00000000..eecf7a0d
--- /dev/null
+++ b/source/epub/templates/container.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0">
+ <rootfiles>
+ <rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/>
+ </rootfiles>
+</container>
diff --git a/source/epub/templates/content.opf b/source/epub/templates/content.opf
new file mode 100644
index 00000000..67f3f5c6
--- /dev/null
+++ b/source/epub/templates/content.opf
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<opf:package xmlns:opf="http://www.idpf.org/2007/opf"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:py="http://genshi.edgewall.org/"
+ unique-identifier="bookid" version="2.0">
+ <opf:metadata >
+ <dc:identifier id="bookid">urn:uuid:${book.UUID}</dc:identifier>
+ <dc:language>${book.lang}</dc:language>
+ <dc:title>${book.title}</dc:title>
+ <py:for each="name, role in book.creators">
+ <dc:creator opf:role="$role">$name</dc:creator>
+ </py:for>
+ <py:for each="beginTag, content, endTag in book.getMetaTags()">
+ ${Markup(beginTag)}$content${Markup(endTag)}
+ </py:for>
+ <opf:meta name="cover" content="${book.coverImage.id}" py:if="book.coverImage"/>
+ </opf:metadata>
+ <opf:manifest>
+ <opf:item id="ncxtoc" media-type="application/x-dtbncx+xml" href="toc.ncx"/>
+ <py:for each="item in book.getAllItems()">
+ <opf:item id="${item.id}" media-type="${item.mimeType}" href="${item.destPath}"/>
+ </py:for>
+ </opf:manifest>
+ <opf:spine toc="ncxtoc">
+ <py:for each="_, item, linear in book.getSpine()">
+ <opf:itemref idref="${item.id}" linear="${'yes' if linear else 'no'}"/>
+ </py:for>
+ </opf:spine>
+ <opf:guide py:if="book.guide">
+ <py:for each="href, title, type in book.getGuide()">
+ <opf:reference href="$href" type="$type" title="$title"/>
+ </py:for>
+ </opf:guide>
+</opf:package>
diff --git a/source/epub/templates/ez-section.html b/source/epub/templates/ez-section.html
new file mode 100644
index 00000000..0a715e7f
--- /dev/null
+++ b/source/epub/templates/ez-section.html
@@ -0,0 +1,17 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:py="http://genshi.edgewall.org/">
+<head>
+ <title>${section.title}</title>
+ <style type="text/css">
+h1 {
+ text-align: center;
+}
+ </style>
+</head>
+<body>
+ <h1>${section.title}</h1>
+ <py:for each="p in section.paragraphs">
+ <p>$p</p>
+ </py:for>
+</body>
+</html>
diff --git a/source/epub/templates/image.html b/source/epub/templates/image.html
new file mode 100644
index 00000000..9a838c7e
--- /dev/null
+++ b/source/epub/templates/image.html
@@ -0,0 +1,16 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:py="http://genshi.edgewall.org/">
+<head>
+ <title>${item.destPath}</title>
+ <style type="text/css">
+div, img {
+ border: 0;
+ margin: 0;
+ padding: 0;
+}
+ </style>
+</head>
+<body>
+ <div><img src="${item.destPath}" alt="${item.destPath}"/></div>
+</body>
+</html>
diff --git a/source/epub/templates/title-page.html b/source/epub/templates/title-page.html
new file mode 100644
index 00000000..de0f55f0
--- /dev/null
+++ b/source/epub/templates/title-page.html
@@ -0,0 +1,22 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:py="http://genshi.edgewall.org/">
+<head>
+ <title>${book.title}</title>
+ <style type="text/css">
+.title, .authors {
+ text-align: center;
+}
+span.author {
+ margin: 1em;
+}
+ </style>
+</head>
+<body>
+ <h1 class="title">${book.title}</h1>
+ <h3 class="authors">
+ <py:for each="creator, _ in book.creators">
+ <span class="author">$creator</span>
+ </py:for>
+ </h3>
+</body>
+</html>
diff --git a/source/epub/templates/toc.html b/source/epub/templates/toc.html
new file mode 100644
index 00000000..b14c9da3
--- /dev/null
+++ b/source/epub/templates/toc.html
@@ -0,0 +1,32 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:py="http://genshi.edgewall.org/">
+<head>
+ <title>${book.title}</title>
+ <style type="text/css">
+.tocEntry-1 {
+}
+.tocEntry-2 {
+ text-indent: 1em;
+}
+.tocEntry-3 {
+ text-indent: 2em;
+}
+.tocEntry-4 {
+ text-indent: 3em;
+}
+ </style>
+</head>
+<body>
+ <py:def function="tocEntry(node)">
+ <div class="tocEntry-${node.depth}">
+ <a href="${node.href}">${node.title}</a>
+ </div>
+ <py:for each="child in node.children">
+ ${tocEntry(child)}
+ </py:for>
+ </py:def>
+ <py:for each="child in book.getTocMapRoot().children">
+ ${tocEntry(child)}
+ </py:for>
+</body>
+</html>
diff --git a/source/epub/templates/toc.ncx b/source/epub/templates/toc.ncx
new file mode 100644
index 00000000..e7dd391a
--- /dev/null
+++ b/source/epub/templates/toc.ncx
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/"
+ xmlns:py="http://genshi.edgewall.org/"
+ version="2005-1">
+ <head>
+ <meta name="dtb:uid" content="urn:uuid:${book.UUID}"/>
+ <meta name="dtb:depth" content="${book.getTocMapHeight()}"/>
+ <meta name="dtb:totalPageCount" content="0"/>
+ <meta name="dtb:maxPageNumber" content="0"/>
+ </head>
+ <docTitle>
+ <text>${book.title}</text>
+ </docTitle>
+ <navMap>
+ <py:def function="navPoint(node)">
+ <navPoint id="navPoint-${node.playOrder}" playOrder="${node.playOrder}">
+ <navLabel><text>${node.title}</text></navLabel>
+ <content src="${node.href}"/>
+ <py:for each="child in node.children">
+ ${navPoint(child)}
+ </py:for>
+ </navPoint>
+ </py:def>
+ <py:for each="child in book.getTocMapRoot().children">
+ ${navPoint(child)}
+ </py:for>
+ </navMap>
+</ncx>
diff --git a/source/export.py b/source/export.py
new file mode 100644
index 00000000..a14d47c0
--- /dev/null
+++ b/source/export.py
@@ -0,0 +1,190 @@
+#! /usr/bin/env python
+#-*- coding: utf-8 -*-
+
+# pyAggr3g470r - A Web based news aggregator.
+# Copyright (C) 2010 Cédric Bonhomme - http://cedricbonhomme.org/
+#
+# For more information : http://bitbucket.org/cedricbonhomme/pyaggr3g470r/
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+__author__ = "Cedric Bonhomme"
+__version__ = "$Revision: 0.1 $"
+__date__ = "$Date: 2011/10/24 $"
+__copyright__ = "Copyright (c) Cedric Bonhomme"
+__license__ = "GPLv3"
+
+#
+# This file contains the export functions of pyAggr3g470r. Indeed
+# it is possible to export the database of articles in different formats:
+# - simple HTML webzine;
+# - text file;
+# - ePub file;
+# - PDF file.
+#
+
+import os
+import hashlib
+
+import utils
+
+
+htmlheader = '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n' + \
+ '<head>' + \
+ '\n\t<title>pyAggr3g470r - News aggregator</title>\n' + \
+ '\t<link rel="stylesheet" type="text/css" href="/css/style.css" />' + \
+ '\n\t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n' + \
+ '</head>\n'
+
+htmlfooter = '<p>This software is under GPLv3 license. You are welcome to copy, modify or' + \
+ ' redistribute the source code according to the' + \
+ ' <a href="http://www.gnu.org/licenses/gpl-3.0.txt">GPLv3</a> license.</p></div>\n' + \
+ '</body>\n</html>'
+
+
+
+def export_html(feeds):
+ """
+ Export the articles given in parameter in a simple Webzine.
+ """
+ index = htmlheader
+ index += "<br />\n<ul>"
+ for feed in feeds.values():
+ # creates a folder for each stream
+ feed_folder = utils.path + "/var/export/webzine/" + \
+ utils.normalize_filename(feed.feed_id)
+ try:
+ os.makedirs(feed_folder)
+ except OSError:
+ # directories already exists (not a problem)
+ pass
+
+
+ index += """<li><a href="%s">%s</a></a></li>\n""" % \
+ (feed.feed_id, feed.feed_title)
+
+ posts = htmlheader
+ for article in feed.articles.values():
+
+ post_file_name = os.path.normpath(feed_folder + "/" + article.article_id + ".html")
+ feed_index = os.path.normpath(feed_folder + "/index.html")
+
+ posts += article.article_date + " - " + \
+ """<a href="./%s.html">%s</a>""" % \
+ (article.article_id, article.article_title[:150]) + "<br />\n"
+
+
+ a_post = htmlheader
+ a_post += '\n<div style="width: 50%; overflow:hidden; text-align: justify; margin:0 auto">\n'
+ a_post += """<h1><a href="%s">%s</a></h1><br />""" % \
+ (article.article_link, article.article_title)
+ a_post += article.article_description
+ a_post += "</div>\n<hr />\n"
+ a_post += """<br />\n<a href="%s">Complete story</a>\n<br />\n""" % (article.article_link,)
+ a_post += "<hr />\n" + htmlfooter
+
+
+ with open(post_file_name, "w") as f:
+ f.write(a_post)
+
+ posts += htmlfooter
+ with open(feed_index, "w") as f:
+ f.write(posts)
+
+ index += "\n</ul>\n<br />"
+ index += htmlfooter
+ with open(utils.path + "/var/export/webzine/" + "index.html", "w") as f:
+ f.write(index)
+
+def export_txt(feeds):
+ """
+ Export the articles given in parameter in text files.
+ """
+ for feed in feeds.values():
+ # creates folder for each stream
+ folder = utils.path + "/var/export/txt/" + \
+ utils.normalize_filename(feed.feed_title.strip().replace(':', '').lower())
+ try:
+ os.makedirs(folder)
+ except OSError:
+ # directories already exists (not a problem)
+ pass
+
+ for article in feed.articles.values():
+ name = article.article_date.strip().replace(' ', '_')
+ name = os.path.normpath(folder + "/" + name + ".txt")
+
+ content = "Title: " + article.article_title + "\n\n\n"
+ content += utils.clear_string(article.article_description)
+
+ with open(name, "w") as f:
+ f.write(content)
+
+def export_epub(feeds):
+ """
+ Export the articles given in parameter in ePub files.
+ """
+ from epub import ez_epub
+ for feed in feeds.values():
+ # creates folder for each stream
+ folder = utils.path + "/var/export/epub/" + \
+ utils.normalize_filename(feed.feed_title.strip().replace(':', '').lower())
+ try:
+ os.makedirs(folder)
+ except OSError:
+ # directories already exists (not a problem)
+ pass
+
+ for article in feed.articles.values():
+ name = article.article_date.strip().replace(' ', '_')
+ name = os.path.normpath(folder + "/" + name + ".epub")
+
+ section = ez_epub.Section()
+ section.title = article.article_title.decode('utf-8')
+ section.paragraphs = [utils.clear_string(article.article_description).decode('utf-8')]
+ ez_epub.makeBook(article.article_title.decode('utf-8'), [feed.feed_title.decode('utf-8')], [section], \
+ name, lang='en-US', cover=None)
+
+def export_pdf(feeds):
+ """
+ Export the articles given in parameter in PDF files.
+ """
+ from xhtml2pdf import pisa
+ import cStringIO as StringIO
+ for feed in feeds.values():
+ # creates folder for each stream
+ folder = utils.path + "/var/export/pdf/" + \
+ utils.normalize_filename(feed.feed_title.strip().replace(':', '').lower())
+ try:
+ os.makedirs(folder)
+ except OSError:
+ # directories already exists (not a problem)
+ pass
+
+ for article in feed.articles.values():
+ name = article.article_date.strip().replace(' ', '_')
+ name = os.path.normpath(folder + "/" + name + ".pdf")
+
+ content = htmlheader
+ content += '\n<div style="width: 50%; overflow:hidden; text-align: justify; margin:0 auto">\n'
+ content += """<h1><a href="%s">%s</a></h1><br />""" % \
+ (article.article_link, article.article_title)
+ content += article.article_description
+ content += "</div>\n<hr />\n"
+ content += htmlfooter
+
+ try:
+ pdf = pisa.CreatePDF(StringIO.StringIO(content), file(name, "wb"))
+ except:
+ pass \ No newline at end of file
diff --git a/source/feedgetter.py b/source/feedgetter.py
new file mode 100755
index 00000000..e3469132
--- /dev/null
+++ b/source/feedgetter.py
@@ -0,0 +1,167 @@
+#! /usr/bin/env python
+#-*- coding: utf-8 -*-
+
+# pyAggr3g470r - A Web based news aggregator.
+# Copyright (C) 2010 Cédric Bonhomme - http://cedricbonhomme.org/
+#
+# For more information : http://bitbucket.org/cedricbonhomme/pyaggr3g470r/
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+__author__ = "Cedric Bonhomme"
+__version__ = "$Revision: 1.0 $"
+__date__ = "$Date: 2010/09/02 $"
+__copyright__ = "Copyright (c) Cedric Bonhomme"
+__license__ = "GPLv3"
+
+import os.path
+import traceback
+import threading
+import feedparser
+import hashlib
+from BeautifulSoup import BeautifulSoup
+
+from datetime import datetime
+
+import utils
+import mongodb
+
+feeds_list = []
+list_of_threads = []
+
+
+class FeedGetter(object):
+ """
+ This class is in charge of retrieving feeds listed in ./var/feed.lst.
+ This class uses feedparser module from Mark Pilgrim.
+ For each feed a new thread is launched.
+ """
+ def __init__(self):
+ """
+ Initializes the base and variables.
+ """
+ # MongoDB connections
+ self.articles = mongodb.Articles()
+
+ def retrieve_feed(self):
+ """
+ Parse the file 'feeds.lst' and launch a thread for each RSS feed.
+ """
+ with open("./var/feed.lst") as f:
+ for a_feed in f:
+ # test if the URL is well formed
+ for url_regexp in utils.url_finders:
+ if url_regexp.match(a_feed):
+ the_good_url = url_regexp.match(a_feed).group(0).replace("\n", "")
+ try:
+ # launch a new thread for the RSS feed
+ thread = threading.Thread(None, self.process, \
+ None, (the_good_url,))
+ thread.start()
+ list_of_threads.append(thread)
+ except:
+ pass
+ break
+
+ # wait for all threads are done
+ for th in list_of_threads:
+ th.join()
+
+ def process(self, the_good_url):
+ """Request the URL
+
+ Executed in a thread.
+ """
+ if utils.detect_url_errors([the_good_url]) == []:
+ # if ressource is available add the articles in the base.
+ self.add_into_database(the_good_url)
+
+ def add_into_database(self, feed_link):
+ """
+ Add the articles of the feed 'a_feed' in the SQLite base.
+ """
+ a_feed = feedparser.parse(feed_link)
+ if a_feed['entries'] == []:
+ return
+ try:
+ feed_image = a_feed.feed.image.href
+ except:
+ feed_image = "/img/feed-icon-28x28.png"
+
+ sha1_hash = hashlib.sha1()
+ sha1_hash.update(feed_link.encode('utf-8'))
+ feed_id = sha1_hash.hexdigest()
+
+ collection_dic = {"feed_id": feed_id, \
+ "type": 0, \
+ "feed_image": feed_image, \
+ "feed_title": utils.clear_string(a_feed.feed.title.encode('utf-8')), \
+ "feed_link": feed_link, \
+ "site_link": a_feed.feed.link.encode('utf-8'), \
+ "mail": False \
+ }
+
+ self.articles.add_collection(collection_dic)
+
+ articles = []
+ for article in a_feed['entries']:
+ description = ""
+ try:
+ # article content
+ description = article.content[0].value
+ except AttributeError:
+ try:
+ # article description
+ description = article.description
+ except Exception, e:
+ description = ""
+ description = str(BeautifulSoup(description))
+ article_title = str(BeautifulSoup(article.title))
+
+ try:
+ post_date = datetime(*article.updated_parsed[:6])
+ except:
+ post_date = datetime(*article.published_parsed[:6])
+
+
+ sha1_hash = hashlib.sha1()
+ sha1_hash.update(article.link.encode('utf-8'))
+ article_id = sha1_hash.hexdigest()
+
+ article = {"article_id": article_id, \
+ "type":1, \
+ "article_date": post_date, \
+ "article_link": article.link.encode('utf-8'), \
+ "article_title": article_title, \
+ "article_content": description, \
+ "article_readed": False, \
+ "article_like": False \
+ }
+
+ articles.append(article)
+
+ self.articles.add_articles(articles, feed_id)
+
+ # send new articles by e-mail if desired.
+ #threading.Thread(None, utils.send_mail, None, (utils.mail_from, utils.mail_to, \
+ #a_feed.feed.title.encode('utf-8'), \
+ #article_title, description) \
+ #).start()
+
+
+
+if __name__ == "__main__":
+ # Point of entry in execution mode
+ feed_getter = FeedGetter()
+ feed_getter.retrieve_feed()
diff --git a/source/img/blogmarks.png b/source/img/blogmarks.png
new file mode 100755
index 00000000..2464e5bb
--- /dev/null
+++ b/source/img/blogmarks.png
Binary files differ
diff --git a/source/img/check-news.png b/source/img/check-news.png
new file mode 100644
index 00000000..cce7df39
--- /dev/null
+++ b/source/img/check-news.png
Binary files differ
diff --git a/source/img/cross.png b/source/img/cross.png
new file mode 100644
index 00000000..1514d51a
--- /dev/null
+++ b/source/img/cross.png
Binary files differ
diff --git a/source/img/diaspora.png b/source/img/diaspora.png
new file mode 100644
index 00000000..fdf8bb72
--- /dev/null
+++ b/source/img/diaspora.png
Binary files differ
diff --git a/source/img/digg.png b/source/img/digg.png
new file mode 100755
index 00000000..097c4600
--- /dev/null
+++ b/source/img/digg.png
Binary files differ
diff --git a/source/img/email-follow.png b/source/img/email-follow.png
new file mode 100644
index 00000000..4505c610
--- /dev/null
+++ b/source/img/email-follow.png
Binary files differ
diff --git a/source/img/favicon.png b/source/img/favicon.png
new file mode 100644
index 00000000..d4d38473
--- /dev/null
+++ b/source/img/favicon.png
Binary files differ
diff --git a/source/img/feed-icon-28x28.png b/source/img/feed-icon-28x28.png
new file mode 100755
index 00000000..d64c669c
--- /dev/null
+++ b/source/img/feed-icon-28x28.png
Binary files differ
diff --git a/source/img/following-article.png b/source/img/following-article.png
new file mode 100644
index 00000000..0e59e459
--- /dev/null
+++ b/source/img/following-article.png
Binary files differ
diff --git a/source/img/hacker-news.png b/source/img/hacker-news.png
new file mode 100644
index 00000000..ce92765d
--- /dev/null
+++ b/source/img/hacker-news.png
Binary files differ
diff --git a/source/img/heart-32x32.png b/source/img/heart-32x32.png
new file mode 100644
index 00000000..09b01cb5
--- /dev/null
+++ b/source/img/heart-32x32.png
Binary files differ
diff --git a/source/img/heart.png b/source/img/heart.png
new file mode 100644
index 00000000..f36f3cfd
--- /dev/null
+++ b/source/img/heart.png
Binary files differ
diff --git a/source/img/heart_open.png b/source/img/heart_open.png
new file mode 100644
index 00000000..e1c6e027
--- /dev/null
+++ b/source/img/heart_open.png
Binary files differ
diff --git a/source/img/history.png b/source/img/history.png
new file mode 100644
index 00000000..2a57cc17
--- /dev/null
+++ b/source/img/history.png
Binary files differ
diff --git a/source/img/identica.png b/source/img/identica.png
new file mode 100644
index 00000000..18b5bd2b
--- /dev/null
+++ b/source/img/identica.png
Binary files differ
diff --git a/source/img/management.png b/source/img/management.png
new file mode 100644
index 00000000..7bcbc384
--- /dev/null
+++ b/source/img/management.png
Binary files differ
diff --git a/source/img/mark-as-read.png b/source/img/mark-as-read.png
new file mode 100644
index 00000000..ffc90910
--- /dev/null
+++ b/source/img/mark-as-read.png
Binary files differ
diff --git a/source/img/pinboard.png b/source/img/pinboard.png
new file mode 100644
index 00000000..6dddc10b
--- /dev/null
+++ b/source/img/pinboard.png
Binary files differ
diff --git a/source/img/previous-article.png b/source/img/previous-article.png
new file mode 100644
index 00000000..fcd9bfd8
--- /dev/null
+++ b/source/img/previous-article.png
Binary files differ
diff --git a/source/img/reddit.png b/source/img/reddit.png
new file mode 100755
index 00000000..2d615f2a
--- /dev/null
+++ b/source/img/reddit.png
Binary files differ
diff --git a/source/img/scoopeo.png b/source/img/scoopeo.png
new file mode 100755
index 00000000..052c7dc8
--- /dev/null
+++ b/source/img/scoopeo.png
Binary files differ
diff --git a/source/img/tuxrss.png b/source/img/tuxrss.png
new file mode 100644
index 00000000..d4d38473
--- /dev/null
+++ b/source/img/tuxrss.png
Binary files differ
diff --git a/source/img/unread.png b/source/img/unread.png
new file mode 100644
index 00000000..d3a641c7
--- /dev/null
+++ b/source/img/unread.png
Binary files differ
diff --git a/source/mongodb.py b/source/mongodb.py
new file mode 100644
index 00000000..d00b453e
--- /dev/null
+++ b/source/mongodb.py
@@ -0,0 +1,253 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+__author__ = "Cedric Bonhomme"
+__version__ = "$Revision: 0.1 $"
+__date__ = "$Date: 2012/03/03 $"
+__revision__ = "$Date: 2012/03/03 $"
+__copyright__ = "Copyright (c) Cedric Bonhomme"
+__license__ = "GPLv3"
+
+import time
+import pymongo
+
+from operator import itemgetter, attrgetter
+
+class Articles(object):
+ """
+ """
+ def __init__(self, url='localhost', port=27017):
+ """
+ Instantiates the connection.
+ """
+ self.connection = pymongo.connection.Connection(url, port)
+ self.db = self.connection.pyaggr3g470r
+
+ def add_collection(self, new_collection):
+ """
+ Creates a new collection for a new feed.
+ """
+ collection = self.db[new_collection["feed_id"]]
+ #collection.create_index([("feed_link", pymongo.ASCENDING)], {"unique":True, "sparse":True})
+ collection.insert(new_collection)
+
+ def add_articles(self, articles, feed_id):
+ """
+ Add article(s) in a collection.
+ """
+ collection = self.db[str(feed_id)]
+
+ collection.create_index([("article_date", pymongo.DESCENDING)], \
+ {"unique":False, "sparse":False})
+
+ for article in articles:
+ cursor = collection.find({"article_id":article["article_id"]})
+ if cursor.count() == 0:
+ collection.insert(article)
+
+ def delete_feed(self, feed_id):
+ """
+ Delete a collection (feed with all articles).
+ """
+ self.db.drop_collection(feed_id)
+
+ def delete_article(self, feed_id, article_id):
+ """
+ Delete an article.
+ """
+ collection = self.db[str(feed_id)]
+ collection.find_and_modify(query={"article_id":article_id}, remove=True)
+
+ def get_collection(self, feed_id):
+ """
+ """
+ return self.db[str(feed_id)].find().next()
+
+ def get_all_articles(self):
+ """
+ Return all articles from all collections.
+ """
+ articles = []
+ collections = self.db.collection_names()
+ for collection_name in collections:
+ collection = self.db[collection_name]
+ articles.extend([article for article in collection.find({'type':1})])
+ return articles
+
+ def get_article(self, feed_id, article_id):
+ """
+ """
+ collection = self.db[str(feed_id)]
+ return collection.find({"article_id":article_id}).next()
+
+ def get_all_collections(self, condition=None):
+ """
+ """
+ feeds = []
+ collections = self.db.collection_names()
+ for collection_name in collections:
+ if collection_name != "system.indexes":
+ if condition is None:
+ cursor = self.db[collection_name].find({"type":0})
+ else:
+ cursor = self.db[collection_name].find({"type":0, condition[0]:condition[1]})
+ if cursor.count() != 0:
+ feeds.append(cursor.next())
+ feeds.sort(key = lambda elem: elem['feed_title'].lower())
+ return feeds
+
+ def get_articles_from_collection(self, feed_id, condition=None):
+ """
+ Return all the articles of a collection.
+ """
+ collection = self.db[str(feed_id)]
+ if condition is None:
+ cursor = collection.find({"type":1})
+ else:
+ cursor = collection.find({"type":1, condition[0]:condition[1]})
+ return cursor.sort([("article_date", pymongo.DESCENDING)])
+
+ def print_articles_from_collection(self, collection_id):
+ """
+ Print the articles of a collection.
+ """
+ collection = self.db[str(collection_id)]
+ cursor = collection.find({"type":1})
+ print "Article for the collection", collection_id
+ for d in cursor:
+ print d
+ print
+
+ def nb_articles(self, feed_id=None):
+ """
+ Return the number of users.
+ """
+ if feed_id is not None:
+ collection = self.db[feed_id]
+ cursor = collection.find({'type':1})
+ return cursor.count()
+ else:
+ nb_articles = 0
+ for feed_id in self.db.collection_names():
+ nb_articles += self.nb_articles(feed_id)
+ return nb_articles
+
+ def nb_favorites(self, feed_id=None):
+ if feed_id is not None:
+ collection = self.db[feed_id]
+ cursor = collection.find({'type':1, 'article_like':True})
+ return cursor.count()
+ else:
+ nb_favorites = 0
+ for feed_id in self.db.collection_names():
+ nb_favorites += self.nb_favorites(feed_id)
+ return nb_favorites
+
+ def nb_mail_notifications(self):
+ """
+ Return the number of subscribed feeds.
+ """
+ nb_mail_notifications = 0
+ for feed_id in self.db.collection_names():
+ collection = self.db[feed_id]
+ cursor = collection.find({'type':0, 'mail':True})
+ nb_mail_notifications += cursor.count()
+ return nb_mail_notifications
+
+ def nb_unread_articles(self, feed_id=None):
+ if feed_id is not None:
+ collection = self.db[feed_id]
+ cursor = collection.find({'article_readed':False})
+ return cursor.count()
+ else:
+ unread_articles = 0
+ for feed_id in self.db.collection_names():
+ unread_articles += self.nb_unread_articles(feed_id)
+ return unread_articles
+
+ def like_article(self, like, feed_id, article_id):
+ """
+ Like or unlike an article.
+ """
+ collection = self.db[str(feed_id)]
+ collection.update({"article_id": article_id}, {"$set": {"article_like": like}})
+
+ def mark_as_read(self, readed, feed_id=None, article_id=None):
+ """
+ """
+ if feed_id != None and article_id != None:
+ collection = self.db[str(feed_id)]
+ collection.update({"article_id": article_id, "article_readed":not readed}, {"$set": {"article_readed": readed}})
+ elif feed_id != None and article_id == None:
+ collection = self.db[str(feed_id)]
+ collection.update({"type": 1, "article_readed":not readed}, {"$set": {"article_readed": readed}}, multi=True)
+ else:
+ for feed_id in self.db.collection_names():
+ self.mark_as_read(readed, feed_id, None)
+
+ def list_collections(self):
+ """
+ List all collections (feed).
+ """
+ collections = self.db.collection_names()
+ return collections
+
+ # Functions on database
+ def drop_database(self):
+ """
+ Drop all the database
+ """
+ self.connection.drop_database('pyaggr3g470r')
+
+
+if __name__ == "__main__":
+ # Point of entry in execution mode.
+ articles = Articles()
+
+
+ # Create a collection for a stream
+ collection_dic = {"collection_id": 42,\
+ "feed_image": "Image", \
+ "feed_title": "Title", \
+ "feed_link": "Link", \
+ "site_title": "Site link", \
+ "mail": True, \
+ }
+
+ #articles.add_collection(collection_dic)
+
+
+
+ # Add an article in the newly created collection
+ article_dic1 = {"article_id": 51, \
+ "article_date": "Today", \
+ "article_link": "Link of the article", \
+ "article_title": "The title", \
+ "article_content": "The content of the article", \
+ "article_readed": True, \
+ "article_like": True \
+ }
+
+ article_dic2 = {"article_id": 52, \
+ "article_date": "Yesterday", \
+ "article_link": "Link", \
+ "article_title": "Hello", \
+ "article_content": "The content of the article", \
+ "article_readed": True, \
+ "article_like": True \
+ }
+
+ #articles.add_articles([article_dic1, article_dic2], 42)
+
+
+ # Print articles of the collection
+ #articles.print_articles_from_collection("http://esr.ibiblio.org/?feed=rss2")
+
+
+ print "All articles:"
+ #print articles.get_all_articles()
+
+
+
+ # Drop the database
+ articles.drop_database() \ No newline at end of file
diff --git a/source/pyAggr3g470r b/source/pyAggr3g470r
new file mode 100755
index 00000000..81f5cea0
--- /dev/null
+++ b/source/pyAggr3g470r
@@ -0,0 +1,130 @@
+#! /usr/bin/env python
+#-*- coding: utf-8 -*-
+
+# pyAggr3g470r - A Web based news aggregator.
+# Copyright (C) 2010 Cédric Bonhomme - http://cedricbonhomme.org/
+#
+# For more information : http://bitbucket.org/cedricbonhomme/pyaggr3g470r/
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+__author__ = "Cedric Bonhomme"
+__version__ = "$Revision: 0.1 $"
+__date__ = "$Date: 2011/06/20 $"
+__copyright__ = "Copyright (c) Cedric Bonhomme"
+__license__ = "GPLv3"
+
+# This control file is inspired from Forban: http://www.foo.be/forban.
+
+import os
+import sys
+import time
+import subprocess
+import platform
+import signal
+
+PATH = os.path.abspath(".")
+SERVICE = "pyAggr3g470r"
+
+def service_start(servicename = None):
+ if servicename is not None:
+ service = servicename + ".py"
+ proc = subprocess.Popen(["python",service], stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
+ time.sleep(0.15)
+ return proc.pid
+ return False
+
+def writepid (processname = None, pid = None):
+ pidpath = os.path.join(PATH,"var",processname+".pid")
+ if processname is not None and pid is not None:
+ f = open (pidpath,"w")
+ f.write(str(pid))
+ f.close()
+ return True
+ else:
+ return False
+
+def checkpid (servicename = None):
+ pidpath = os.path.join(PATH,"var",servicename+".pid")
+ if os.path.exists(pidpath):
+ return True
+ else:
+ return False
+
+def pidof(processname = None):
+ pidpath = os.path.join(PATH,"var",processname+".pid")
+ if processname is not None and os.path.exists(pidpath):
+ f = open (pidpath)
+ pid = f.read()
+ f.close()
+ return pid
+ else:
+ return False
+
+def rmpid (processname = None):
+ pidpath = os.path.join(PATH, "var", processname + ".pid")
+ if os.path.exists(pidpath):
+ os.unlink(pidpath)
+ return True
+ else:
+ return False
+
+def start():
+ if not checkpid(servicename = SERVICE):
+ pid = service_start(servicename = SERVICE)
+ writepid(processname = SERVICE, pid = pid)
+ print SERVICE + " is starting with pid: " + pidof(processname=SERVICE)
+ else:
+ print SERVICE + " could not be started (pid exists)"
+ retval=False
+
+def stop():
+ print "Stopping pyAggr3g470r..."
+ retval=True
+ pid = pidof(processname=SERVICE)
+ if pid:
+ if platform.system() == "Windows":
+ import win32api
+ import win32con
+ phandle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0, int(pid))
+ win32api.TerminateProcess(phandle, 0)
+ win32api.CloseHandle(phandle)
+ rmpid(processname=SERVICE)
+ else:
+ try:
+ os.kill(int(pid), signal.SIGKILL)
+ except OSError, e:
+ print SERVICE + " unsuccessfully stopped"
+ retval = False
+ print SERVICE
+ rmpid(processname=SERVICE)
+ return retval
+
+def usage():
+ print "pyAggr3g470r (start|stop|restart)"
+ exit (1)
+
+if __name__ == "__main__":
+ # Point of entry in execution mode.
+ if len(sys.argv) == 1:
+ usage()
+ elif sys.argv[1] == "start":
+ start()
+ elif sys.argv[1] == "stop":
+ stop()
+ elif sys.argv[1] == "restart":
+ stop()
+ start()
+ else:
+ usage()
diff --git a/source/pyAggr3g470r.py b/source/pyAggr3g470r.py
new file mode 100755
index 00000000..1284ea3e
--- /dev/null
+++ b/source/pyAggr3g470r.py
@@ -0,0 +1,1271 @@
+#! /usr/bin/env python
+#-*- coding: utf-8 -*-
+
+# pyAggr3g470r - A Web based news aggregator.
+# Copyright (C) 2010-2012 Cédric Bonhomme - http://cedricbonhomme.org/
+#
+# For more information : http://bitbucket.org/cedricbonhomme/pyaggr3g470r/
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+__author__ = "Cedric Bonhomme"
+__version__ = "$Revision: 3.1 $"
+__date__ = "$Date: 2010/01/29 $"
+__revision__ = "$Date: 2012/03/09 $"
+__copyright__ = "Copyright (c) Cedric Bonhomme"
+__license__ = "GPLv3"
+
+#
+# This file contains the "Root" class which describes
+# all pages of pyAggr3g470r. These pages are:
+# - main page;
+# - management;
+# - history;
+# - favorites;
+# - notifications;
+# - unread;
+# - feed summary.
+#
+
+import os
+import re
+import time
+import cherrypy
+import calendar
+
+from collections import Counter
+import datetime
+
+import utils
+import export
+import mongodb
+import feedgetter
+from qrcode.pyqrnative.PyQRNative import QRCode, QRErrorCorrectLevel, CodeOverflowException
+from qrcode import qr
+
+
+def error_page_404(status, message, traceback, version):
+ """
+ Display an error if the page does not exist.
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += "<br /><br />Error %s - This page does not exist." % status
+ html += "\n<hr />\n" + htmlfooter
+ return html
+
+def handle_error():
+ """
+ Handle different type of errors.
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += "<br /><br />Sorry, an error occured"
+ html += "\n<hr />\n" + htmlfooter
+ cherrypy.response.status = 500
+ cherrypy.response.body = [html]
+
+def htmlheader(nb_unread_articles=""):
+ """
+ Return the header of the HTML page with the number of unread articles
+ in the 'title' HTML tag..
+ """
+ return '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n' + \
+ '<head>' + \
+ '\n\t<title>'+ nb_unread_articles +'pyAggr3g470r - News aggregator</title>\n' + \
+ '\t<link rel="stylesheet" type="text/css" href="/css/style.css" />' + \
+ '\n\t<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n' + \
+ '\n\t<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>\n' + \
+ '</head>\n'
+
+htmlfooter = '<p>This software is under GPLv3 license. You are welcome to copy, modify or' + \
+ ' redistribute the source code according to the' + \
+ ' <a href="http://www.gnu.org/licenses/gpl-3.0.txt">GPLv3</a> license.</p></div>\n' + \
+ '</body>\n</html>'
+
+htmlnav = '<body>\n<h1><div class="right innerlogo"><a href="/"><img src="/img/tuxrss.png"' + \
+ """ title="What's new today?"/></a>""" + \
+ '</div><a name="top"><a href="/">pyAggr3g470r - News aggregator</a></a></h1>\n<a' + \
+ ' href="http://bitbucket.org/cedricbonhomme/pyaggr3g470r/" rel="noreferrer" target="_blank">' + \
+ 'pyAggr3g470r (source code)</a>'
+
+
+class Root:
+ """
+ Root class.
+ All pages of pyAggr3g470r are described in this class.
+ """
+ def __init__(self):
+ """
+ """
+ self.mongo = mongodb.Articles(utils.MONGODB_ADDRESS, utils.MONGODB_PORT)
+
+ def index(self):
+ """
+ Main page containing the list of feeds and articles.
+ """
+ feeds = self.mongo.get_all_collections()
+ nb_unread_articles = self.mongo.nb_unread_articles()
+ nb_favorites = self.mongo.nb_favorites()
+ nb_mail_notifications = self.mongo.nb_mail_notifications()
+
+ # if there are unread articles, display the number in the tab of the browser
+ html = htmlheader((nb_unread_articles and \
+ ['(' + str(nb_unread_articles) +') '] or \
+ [""])[0])
+ html += htmlnav
+ html += self.create_right_menu()
+ html += """<div class="left inner">\n"""
+
+ if feeds:
+ html += '<a href="/management/"><img src="/img/management.png" title="Management" /></a>\n'
+ html += '<a href="/history/"><img src="/img/history.png" title="History" /></a>\n'
+ html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n'
+
+ html += """<a href="/favorites/"><img src="/img/heart-32x32.png" title="Your favorites (%s)" /></a>\n""" % \
+ (nb_favorites,)
+
+ html += """<a href="/notifications/"><img src="/img/email-follow.png" title="Active e-mail notifications (%s)" /></a>\n""" % \
+ (nb_mail_notifications,)
+
+ html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
+ if nb_unread_articles != 0:
+ html += '<a href="/mark_as_read/"><img src="/img/mark-as-read.png" title="Mark articles as read" /></a>\n'
+ html += """<a href="/unread/"><img src="/img/unread.png" title="Unread article(s): %s" /></a>\n""" % \
+ (nb_unread_articles,)
+ html += '<a accesskey="F" href="/fetch/"><img src="/img/check-news.png" title="Check for news" /></a>\n'
+
+
+ # The main page display all the feeds.
+ for feed in feeds:
+ html += """<h2><a name="%s"><a href="%s" rel="noreferrer"
+ target="_blank">%s</a></a>
+ <a href="%s" rel="noreferrer"
+ target="_blank"><img src="%s" width="28" height="28" /></a></h2>\n""" % \
+ (feed["feed_id"], feed["feed_link"], feed["feed_title"], \
+ feed["feed_link"], feed["feed_image"])
+
+ # The main page display only 10 articles by feeds.
+ for article in self.mongo.get_articles_from_collection(feed["feed_id"])[:10]:
+ if article["article_readed"] == False:
+ # not readed articles are in bold
+ not_read_begin, not_read_end = "<b>", "</b>"
+ else:
+ not_read_begin, not_read_end = "", ""
+
+ # display a heart for faved articles
+ if article["article_like"] == True:
+ like = """ <img src="/img/heart.png" title="I like this article!" />"""
+ else:
+ like = ""
+
+ # Descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content.split(' ')[:55])
+ else:
+ description = "No description."
+ # Title of the article
+ article_title = article["article_title"]
+ if len(article_title) >= 110:
+ article_title = article_title[:110] + " ..."
+
+ # a description line per article (date, title of the article and
+ # CSS description tooltips on mouse over)
+ html += article["article_date"].ctime() + " - " + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s%s%s<span class="classic">%s</span></a>""" % \
+ (feed["feed_id"], article["article_id"], not_read_begin, \
+ article_title, not_read_end, description) + like + "<br />\n"
+ html += "<br />\n"
+
+ # some options for the current feed
+ html += """<a href="/articles/%s">All articles</a>&nbsp;&nbsp;&nbsp;""" % (feed["feed_id"],)
+ html += """<a href="/feed/%s">Feed summary</a>&nbsp;&nbsp;&nbsp;""" % (feed["feed_id"],)
+ if self.mongo.nb_unread_articles(feed["feed_id"]) != 0:
+ html += """&nbsp;&nbsp;<a href="/mark_as_read/Feed_FromMainPage:%s">Mark all as read</a>""" % (feed["feed_id"],)
+ html += """&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="/unread/%s" title="Unread article(s)">Unread article(s) (%s)</a>""" % (feed["feed_id"], self.mongo.nb_unread_articles(feed["feed_id"]))
+ if feed["mail"] == "0":
+ html += """<br />\n<a href="/mail_notification/1:%s" title="By e-mail">Stay tuned</a>""" % (feed["feed_id"],)
+ else:
+ html += """<br />\n<a href="/mail_notification/0:%s" title="By e-mail">Stop staying tuned</a>""" % (feed["feed_id"],)
+ html += """<h4><a href="/#top">Top</a></h4>"""
+ html += "<hr />\n"
+ html += htmlfooter
+ return html
+
+ index.exposed = True
+
+
+ def create_right_menu(self):
+ """
+ Create the right menu.
+ """
+ html = """<div class="right inner">\n"""
+ html += """<form method=get action="/search/"><input type="search" name="query" value="" placeholder="Search articles" maxlength=2048 autocomplete="on"></form>\n"""
+ html += "<hr />\n"
+ # insert the list of feeds in the menu
+ html += self.create_list_of_feeds()
+ html += "</div>\n"
+
+ return html
+
+ def create_list_of_feeds(self):
+ """
+ Create the list of feeds.
+ """
+ feeds = self.mongo.get_all_collections()
+ html = """<div class="nav_container">Your feeds (%s):<br />\n""" % len(feeds)
+ for feed in feeds:
+ if self.mongo.nb_unread_articles(feed["feed_id"]) != 0:
+ # not readed articles are in bold
+ not_read_begin, not_read_end = "<b>", "</b>"
+ else:
+ not_read_begin, not_read_end = "", ""
+ html += """<div><a href="/#%s">%s</a> (<a href="/unread/%s" title="Unread article(s)">%s%s%s</a> / %s)</div>""" % \
+ (feed["feed_id"], feed["feed_title"], feed["feed_id"], not_read_begin, \
+ self.mongo.nb_unread_articles(feed["feed_id"]), not_read_end, self.mongo.nb_articles(feed["feed_id"]))
+ return html + "</div>"
+
+
+ def management(self, max_nb_articles=5):
+ """
+ Management page.
+ Allows adding and deleting feeds. Export functions of the MongoDB data base
+ and display some statistics.
+ """
+ feeds = self.mongo.get_all_collections()
+ nb_mail_notifications = self.mongo.nb_mail_notifications()
+ nb_favorites = self.mongo.nb_favorites()
+ nb_articles = self.mongo.nb_articles()
+ nb_unread_articles = self.mongo.nb_unread_articles()
+
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">\n"""
+ html += "<h1>Add Feeds</h1>\n"
+ # Form: add a feed
+ html += """<form method=get action="/add_feed/"><input type="url" name="url" placeholder="URL of a site" maxlength=2048 autocomplete="off">\n<input type="submit" value="OK"></form>\n"""
+
+ if feeds:
+ # Form: delete a feed
+ html += "<h1>Delete Feeds</h1>\n"
+ html += """<form method=get action="/remove_feed/"><select name="feed_id">\n"""
+ for feed in feeds:
+ html += """\t<option value="%s">%s</option>\n""" % (feed["feed_id"], feed["feed_title"])
+ html += """</select><input type="submit" value="OK"></form>\n"""
+
+ html += """<p>Active e-mail notifications: <a href="/notifications/">%s</a></p>\n""" % \
+ (nb_mail_notifications,)
+ html += """<p>You like <a href="/favorites/">%s</a> article(s).</p>\n""" % \
+ (nb_favorites, )
+
+ html += "<hr />\n"
+
+ # Informations about the data base of articles
+ html += """<p>%s article(s) are loaded from the database with
+ <a href="/unread/">%s unread article(s)</a>.<br />\n""" % \
+ (nb_articles, nb_unread_articles)
+ #html += """Database: %s.\n<br />Size: %s bytes.<br />\n""" % \
+ #(os.path.abspath(utils.sqlite_base), os.path.getsize(utils.sqlite_base))
+ html += '<a href="/statistics/">Advanced statistics.</a></p>\n'
+
+ html += """<form method=get action="/fetch/">\n<input type="submit" value="Fetch all feeds"></form>\n"""
+ html += """<form method=get action="/drop_base">\n<input type="submit" value="Delete all articles"></form>\n"""
+
+
+ html += '<form method=get action="/set_max_articles/">\n'
+ html += "For each feed only load the "
+ html += """<input type="number" name="max_nb_articles" value="%s" min="1" step="1" size="2">\n""" % (max_nb_articles)
+ html += " last articles."
+ if utils.MAX_NB_ARTICLES == -1:
+ html += "<br />All articles are currently loaded.\n"
+ else:
+ html += "<br />For each feed only " + str(utils.MAX_NB_ARTICLES) + " articles are currently loaded. "
+ html += '<a href="/set_max_articles/-1">Load all articles.</a><br />\n'
+ html += "</form>\n"
+
+ # Export functions
+ html += "<h1>Export articles</h1>\n\n"
+ html += """<form method=get action="/export/"><select name="export_method">\n"""
+ html += """\t<option value="export_html" selected='selected'>HTML (simple Webzine)</option>\n"""
+ html += """\t<option value="export_epub">ePub</option>\n"""
+ html += """\t<option value="export_pdf">PDF</option>\n"""
+ html += """\t<option value="export_txt">Text</option>\n"""
+ html += """</select>\n\t<input type="submit" value="Export">\n</form>\n"""
+ html += "<hr />"
+ html += htmlfooter
+ return html
+
+ management.exposed = True
+
+
+ def statistics(self, word_size=6):
+ """
+ More advanced statistics.
+ """
+ articles = self.mongo.get_all_articles()
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">\n"""
+
+ # Some statistics (most frequent word)
+ if articles:
+ top_words = utils.top_words(articles, n=50, size=int(word_size))
+ html += "<h1>Statistics</h1>\n<br />\n"
+ # Tags cloud
+ html += 'Minimum size of a word:'
+ html += '<form method=get action="/statistics/">'
+ html += """<input type="number" name="word_size" value="%s" min="2" max="15" step="1" size="2">""" % (word_size)
+ html += '<input type="submit" value="OK"></form>\n'
+ html += '<br /><h3>Tag cloud</h3>\n'
+ html += '<div style="width: 35%; overflow:hidden; text-align: justify">' + \
+ utils.tag_cloud(top_words) + '</div>'
+ html += "<hr />\n"
+
+ html += htmlfooter
+ return html
+
+ statistics.exposed = True
+
+
+ def search(self, query=None):
+ """
+ Simply search for the string 'query'
+ in the description of the article.
+ """
+ param, _, value = query.partition(':')
+ wordre = re.compile(r'\b%s\b' % param, re.I)
+ feed_id = None
+ if param == "Feed":
+ feed_id, _, query = value.partition(':')
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ html += """<h1>Articles containing the string <i>%s</i></h1><br />""" % (query,)
+
+ if feed_id is not None:
+ for article in self.feeds[feed_id].articles.values():
+ article_content = utils.clear_string(article.article_description)
+ if not article_content:
+ utils.clear_string(article.article_title)
+ if wordre.findall(article_content) != []:
+ if article.article_readed == "0":
+ # not readed articles are in bold
+ not_read_begin, not_read_end = "<b>", "</b>"
+ else:
+ not_read_begin, not_read_end = "", ""
+
+ html += article.article_date + " - " + not_read_begin + \
+ """<a href="/article/%s:%s" rel="noreferrer" target="_blank">%s</a>""" % \
+ (feed_id, article.article_id, article.article_title) + \
+ not_read_end + """<br />\n"""
+ else:
+ feeds = self.mongo.get_all_collections()
+ for feed in feeds:
+ new_feed_section = True
+ for article in self.mongo.get_articles_from_collection(feed["feed_id"]):
+ article_content = utils.clear_string(article["article_content"])
+ if not article_content:
+ utils.clear_string(article["article_title"])
+ if wordre.findall(article_content) != []:
+ if new_feed_section is True:
+ new_feed_section = False
+ html += """<h2><a href="/articles/%s" rel="noreferrer" target="_blank">%s</a><a href="%s" rel="noreferrer" target="_blank"><img src="%s" width="28" height="28" /></a></h2>\n""" % \
+ (feed["feed_id"], feed["feed_title"], feed["feed_link"], feed["feed_image"])
+
+ if article["article_readed"] == False:
+ # not readed articles are in bold
+ not_read_begin, not_read_end = "<b>", "</b>"
+ else:
+ not_read_begin, not_read_end = "", ""
+
+ # display a heart for faved articles
+ if article["article_like"] == True:
+ like = """ <img src="/img/heart.png" title="I like this article!" />"""
+ else:
+ like = ""
+
+ # descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content[:500].split(' ')[:-1])
+ else:
+ description = "No description."
+
+ # a description line per article (date, title of the article and
+ # CSS description tooltips on mouse over)
+ html += article["article_date"].ctime() + " - " + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s%s%s<span class="classic">%s</span></a>""" % \
+ (feed["feed_id"], article["article_id"], not_read_begin, \
+ article["article_title"][:150], not_read_end, description) + like + "<br />\n"
+ html += "<hr />"
+ html += htmlfooter
+ return html
+
+ search.exposed = True
+
+
+ def fetch(self):
+ """
+ Fetch all feeds.
+ """
+ feed_getter = feedgetter.FeedGetter()
+ feed_getter.retrieve_feed()
+ return self.index()
+
+ fetch.exposed = True
+
+
+ def article(self, param):
+ """
+ Display the article in parameter in a new Web page.
+ """
+ try:
+ feed_id, article_id = param.split(':')
+ feed = self.mongo.get_collection(feed_id)
+ articles = self.mongo.get_articles_from_collection(feed_id)
+ article = self.mongo.get_article(feed_id, article_id)
+ except:
+ return self.error_page("Bad URL. This article do not exists.")
+ html = htmlheader()
+ html += htmlnav
+ html += """<div>"""
+
+ if article["article_readed"] == False:
+ # if the current article is not yet readed, update the database
+ self.mark_as_read("Article:"+article["article_id"]+":"+feed["feed_id"])
+
+ html += '\n<div style="width: 50%; overflow:hidden; text-align: justify; margin:0 auto">\n'
+ # Title of the article
+ html += """<h1><i>%s</i> from <a href="/feed/%s">%s</a></h1>\n<br />\n""" % \
+ (article["article_title"], feed_id, feed["feed_title"])
+ if article["article_like"] == True:
+ html += """<a href="/like/0:%s:%s"><img src="/img/heart.png" title="I like this article!" /></a>""" % \
+ (feed_id, article["article_id"])
+ else:
+ html += """<a href="/like/1:%s:%s"><img src="/img/heart_open.png" title="Click if you like this article." /></a>""" % \
+ (feed_id, article["article_id"])
+ html += """&nbsp;&nbsp;<a href="/delete_article/%s:%s"><img src="/img/cross.png" title="Delete this article" /></a>""" % \
+ (feed_id, article["article_id"])
+ html += "<br /><br />"
+
+ # Description (full content) of the article
+ description = article["article_content"]
+ if description:
+ p = re.compile(r'<code><')
+ q = re.compile(r'></code>')
+
+ description = p.sub('<code>&lt;', description)
+ description = q.sub('&gt;</code>', description)
+
+ html += description + "\n<br /><br /><br />"
+ else:
+ html += "No description available.\n<br /><br /><br />"
+
+ # Generation of the QR Code for the current article
+ try:
+ os.makedirs("./var/qrcode/")
+ except OSError:
+ pass
+ if not os.path.isfile("./var/qrcode/" + article_id + ".png"):
+ # QR Code generation
+ try:
+ if len(utils.clear_string(description)) > 4296:
+ raise Exception()
+ f = qr.QRUrl(url = utils.clear_string(description))
+ f.make()
+ except:
+ f = qr.QRUrl(url = article["article_link"])
+ f.make()
+ f.save("./var/qrcode/"+article_id+".png")
+
+ # Previous and following articles
+ articles_list = articles.distinct("article_id")
+ try:
+ following = articles[articles_list.index(article_id) - 1]
+ html += """<div style="float:right;"><a href="/article/%s:%s" title="%s"><img src="/img/following-article.png" /></a></div>\n""" % \
+ (feed_id, following["article_id"], following["article_title"])
+ except Exception, e:
+ print e
+ try:
+ previous = articles[articles_list.index(article_id) + 1]
+ except:
+ previous = articles[0]
+ finally:
+ html += """<div style="float:left;"><a href="/article/%s:%s" title="%s"><img src="/img/previous-article.png" /></a></div>\n""" % \
+ (feed_id, previous["article_id"], previous["article_title"])
+
+ html += "\n</div>\n"
+
+ # Footer menu
+ html += "<hr />\n"
+ html += """\n<a href="/plain_text/%s:%s">Plain text</a>\n""" % (feed_id, article["article_id"])
+ html += """ - <a href="/epub/%s:%s">Export to EPUB</a>\n""" % (feed_id, article["article_id"])
+ html += """<br />\n<a href="%s">Complete story</a>\n<br />\n""" % (article["article_link"],)
+
+ # Share this article:
+ html += "Share this article:<br />\n"
+ # on Diaspora
+ html += """<a href="javascript:(function(){f='https://%s/bookmarklet?url=%s&amp;title=%s&amp;notes=%s&amp;v=1&amp;';a=function(){if(!window.open(f+'noui=1&amp;jump=doclose','diasporav1','location=yes,links=no,scrollbars=no,toolbar=no,width=620,height=250'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()">\n\t
+ <img src="/img/diaspora.png" title="Share on Diaspora" /></a>\n""" % \
+ (utils.DIASPORA_POD, article["article_link"], article["article_title"], "via pyAggr3g470r")
+
+ # on Identi.ca
+ html += """\n\n<a href="http://identi.ca/index.php?action=newnotice&status_textarea=%s: %s" title="Share on Identi.ca" target="_blank"><img src="/img/identica.png" /></a>""" % \
+ (article["article_title"], article["article_link"])
+
+ # on Hacker News
+ html += """\n\n<a href='javascript:window.location="http://news.ycombinator.com/submitlink?u="+encodeURIComponent("%s")+"&t="+encodeURIComponent("%s")'><img src="/img/hacker-news.png" title="Share on Hacker News" /></a>""" % \
+ (article["article_link"], article["article_title"])
+
+ # on Pinboard
+ html += """\n\n\t<a href="https://api.pinboard.in/v1/posts/add?url=%s&description=%s"
+ rel="noreferrer" target="_blank">\n
+ <img src="/img/pinboard.png" title="Share on Pinboard" /></a>""" % \
+ (article["article_link"], article["article_title"])
+
+ # on Digg
+ html += """\n\n\t<a href="http://digg.com/submit?url=%s&title=%s"
+ rel="noreferrer" target="_blank">\n
+ <img src="/img/digg.png" title="Share on Digg" /></a>""" % \
+ (article["article_link"], article["article_title"])
+ # on reddit
+ html += """\n\n\t<a href="http://reddit.com/submit?url=%s&title=%s"
+ rel="noreferrer" target="_blank">\n
+ <img src="/img/reddit.png" title="Share on reddit" /></a>""" % \
+ (article["article_link"], article["article_title"])
+ # on Scoopeo
+ html += """\n\n\t<a href="http://scoopeo.com/scoop/new?newurl=%s&title=%s"
+ rel="noreferrer" target="_blank">\n
+ <img src="/img/scoopeo.png" title="Share on Scoopeo" /></a>""" % \
+ (article["article_link"], article["article_title"])
+ # on Blogmarks
+ html += """\n\n\t<a href="http://blogmarks.net/my/new.php?url=%s&title=%s"
+ rel="noreferrer" target="_blank">\n
+ <img src="/img/blogmarks.png" title="Share on Blogmarks" /></a>""" % \
+ (article["article_link"], article["article_title"])
+
+ # Google +1 button
+ html += """\n\n<g:plusone size="standard" count="true" href="%s"></g:plusone>""" % \
+ (article["article_link"],)
+
+
+ # QRCode (for smartphone)
+ html += """<br />\n<a href="/var/qrcode/%s.png"><img src="/var/qrcode/%s.png" title="Share with your smartphone" width="500" height="500" /></a>""" % (article_id, article_id)
+ html += "<hr />\n" + htmlfooter
+ return html
+
+ article.exposed = True
+
+
+ def feed(self, feed_id, word_size=6):
+ """
+ This page gives summary informations about a feed (number of articles,
+ unread articles, average activity, tag cloud, e-mail notification and
+ favourite articles for the current feed.
+ """
+ try:
+ feed = self.mongo.get_collection(feed_id)
+ articles = self.mongo.get_articles_from_collection(feed_id)
+ except KeyError:
+ return self.error_page("This feed do not exists.")
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ html += "<p>The feed <b>" + feed["feed_title"] + "</b> contains <b>" + str(self.mongo.nb_articles(feed_id)) + "</b> articles. "
+ html += "Representing " + str((round(float(self.mongo.nb_articles(feed_id)) / 1000, 4)) * 100) + " % of the total " #hack
+ html += "(" + str(1000) + ").</p>"
+ if articles != []:
+ html += "<p>" + (self.mongo.nb_unread_articles(feed_id) == 0 and ["All articles are read"] or [str(self.mongo.nb_unread_articles(feed_id)) + \
+ " unread article" + (self.mongo.nb_unread_articles(feed_id) == 1 and [""] or ["s"])[0]])[0] + ".</p>"
+ if feed["mail"] == True:
+ html += """<p>You are receiving articles from this feed to the address: <a href="mail:%s">%s</a>. """ % \
+ (utils.mail_to, utils.mail_to)
+ html += """<a href="/mail_notification/0:%s">Stop</a> receiving articles from this feed.</p>""" % \
+ (feed[feed_id], )
+
+ if articles != []:
+ last_article = utils.string_to_datetime(str(articles[0]["article_date"]))
+ first_article = utils.string_to_datetime(str(articles[self.mongo.nb_articles(feed_id)-2]["article_date"]))
+ delta = last_article - first_article
+ delta_today = datetime.datetime.fromordinal(datetime.date.today().toordinal()) - last_article
+ html += "<p>The last article was posted " + str(abs(delta_today.days)) + " day(s) ago.</p>"
+ if delta.days > 0:
+ html += """<p>Daily average: %s,""" % (str(round(float(self.mongo.nb_articles(feed_id))/abs(delta.days), 2)),)
+ html += """ between the %s and the %s.</p>\n""" % \
+ (str(articles[self.mongo.nb_articles(feed_id)-2]["article_date"])[:10], str(articles[0]["article_date"])[:10])
+
+ html += "<br /><h1>Recent articles</h1>"
+ for article in articles[:10]:
+ if article["article_readed"] == False:
+ # not readed articles are in bold
+ not_read_begin, not_read_end = "<b>", "</b>"
+ else:
+ not_read_begin, not_read_end = "", ""
+
+ # display a heart for faved articles
+ if article["article_like"] == True:
+ like = """ <img src="/img/heart.png" title="I like this article!" />"""
+ else:
+ like = ""
+
+ # Descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content[:500].split(' ')[:-1])
+ else:
+ description = "No description."
+ # Title of the article
+ article_title = article["article_title"]
+ if len(article_title) >= 110:
+ article_title = article_title[:110] + " ..."
+
+ # a description line per article (date, title of the article and
+ # CSS description tooltips on mouse over)
+ html += article["article_date"].ctime() + " - " + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s%s%s<span class="classic">%s</span></a>""" % \
+ (feed["feed_id"], article["article_id"], not_read_begin, \
+ article_title, not_read_end, description) + like + "<br />\n"
+ html += "<br />\n"
+ html += """<a href="/articles/%s">All articles</a>&nbsp;&nbsp;&nbsp;""" % (feed["feed_id"],)
+
+ favs = [article for article in articles if article["article_like"] == True]
+ if len(favs) != 0:
+ html += "<br /></br /><h1>Your favorites articles for this feed</h1>"
+ for article in favs:
+ if article["like"] == True:
+ # descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content[:500].split(' ')[:-1])
+ else:
+ description = "No description."
+
+ # a description line per article (date, title of the article and
+ # CSS description tooltips on mouse over)
+ html += article["article_date"].ctime() + " - " + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s<span class="classic">%s</span></a><br />\n""" % \
+ (feed["feed_id"], article["article_id"], article["article_title"][:150], description)
+
+
+ # This section enables the user to edit informations about
+ # the current feed:
+ # - feed logo;
+ # - feed name;
+ # - URL of the feed (not the site);
+ html += "<br />\n<h1>Edit this feed</h1>\n"
+ html += '\n\n<form method=post action="/change_feed_name/">' + \
+ '<input type="text" name="new_feed_name" value="" ' + \
+ 'placeholder="Enter a new name (then press Enter)." maxlength=2048 autocomplete="on" size="50" />' + \
+ """<input type="hidden" name="feed_url" value="%s" /></form>\n""" % \
+ (feed["feed_link"],)
+ html += '\n\n<form method=post action="/change_feed_url/">' + \
+ '<input type="url" name="new_feed_url" value="" ' + \
+ 'placeholder="Enter a new URL in order to retrieve articles (then press Enter)." maxlength=2048 autocomplete="on" size="50" />' + \
+ """<input type="hidden" name="old_feed_url" value="%s" /></form>\n""" % \
+ (feed["feed_link"],)
+ html += '\n\n<form method=post action="/change_feed_logo/">' + \
+ '<input type="url" name="new_feed_logo" value="" ' + \
+ 'placeholder="Enter the URL of the logo (then press Enter)." maxlength=2048 autocomplete="on" size="50" />' + \
+ """<input type="hidden" name="feed_url" value="%s" /></form>\n""" % \
+ (feed["feed_link"],)
+
+ dic = {}
+ top_words = utils.top_words(articles = self.mongo.get_articles_from_collection(feed_id), n=50, size=int(word_size))
+ html += "</br /><h1>Tag cloud</h1>\n<br />\n"
+ # Tags cloud
+ html += 'Minimum size of a word:'
+ html += """<form method=get action="/feed/%s">""" % (feed["feed_id"],)
+ html += """<input type="number" name="word_size" value="%s" min="2" max="15" step="1" size="2">""" % (word_size,)
+ html += '<input type="submit" value="OK"></form>\n'
+ html += '<div style="width: 35%; overflow:hidden; text-align: justify">' + \
+ utils.tag_cloud(top_words) + '</div>'
+
+ html += "<br />"
+ html += "<hr />"
+ html += htmlfooter
+ return html
+
+ feed.exposed = True
+
+
+ def articles(self, feed_id):
+ """
+ This page displays all articles of a feed.
+ """
+ try:
+ feed = self.mongo.get_collection(feed_id)
+ articles = self.mongo.get_articles_from_collection(feed_id)
+ except KeyError:
+ return self.error_page("This feed do not exists.")
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="right inner">\n"""
+ html += """<a href="/mark_as_read/Feed:%s">Mark all articles from this feed as read</a>""" % (feed_id,)
+ html += """<br />\n<form method=get action="/search/%s"><input type="search" name="query" value="" placeholder="Search this feed" maxlength=2048 autocomplete="on"></form>\n""" % ("Feed:"+feed_id,)
+ html += "<hr />\n"
+ html += self.create_list_of_feeds()
+ html += """</div> <div class="left inner">"""
+ html += """<h1>Articles of the feed <i>%s</i></h1><br />""" % (feed["feed_title"],)
+
+ for article in articles:
+
+ if article["article_readed"] == False:
+ # not readed articles are in bold
+ not_read_begin, not_read_end = "<b>", "</b>"
+ else:
+ not_read_begin, not_read_end = "", ""
+
+ if article["article_like"] == True:
+ like = """ <img src="/img/heart.png" title="I like this article!" />"""
+ else:
+ like = ""
+
+ # descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content[:500].split(' ')[:-1])
+ else:
+ description = "No description."
+
+ # a description line per article (date, title of the article and
+ # CSS description tooltips on mouse over)
+ html += article["article_date"].ctime() + " - " + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s%s%s<span class="classic">%s</span></a>""" % \
+ (feed_id, article["article_id"], not_read_begin, \
+ article["article_title"][:150], not_read_end, description) + like + "<br />\n"
+
+ html += """\n<h4><a href="/">All feeds</a></h4>"""
+ html += "<hr />\n"
+ html += htmlfooter
+ return html
+
+ articles.exposed = True
+
+
+ def unread(self, feed_id=""):
+ """
+ This page displays all unread articles of a feed.
+ """
+ feeds = self.mongo.get_all_collections()
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ if self.mongo.nb_unread_articles() != 0:
+
+ # List unread articles of all the database
+ if feed_id == "":
+ html += "<h1>Unread article(s)</h1>"
+ html += """\n<br />\n<a href="/mark_as_read/">Mark articles as read</a>\n<hr />\n"""
+ for feed in feeds:
+ new_feed_section = True
+ nb_unread = 0
+
+ # For all unread article of the current feed.
+ for article in self.mongo.get_articles_from_collection(feed["feed_id"], condition=("article_readed", False)):
+ nb_unread += 1
+ if new_feed_section is True:
+ new_feed_section = False
+ html += """<h2><a name="%s"><a href="%s" rel="noreferrer" target="_blank">%s</a></a><a href="%s" rel="noreferrer" target="_blank"><img src="%s" width="28" height="28" /></a></h2>\n""" % \
+ (feed["feed_id"], feed["site_link"], feed["feed_title"], feed["feed_link"], feed["feed_image"])
+
+ # descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content[:500].split(' ')[:-1])
+ else:
+ description = "No description."
+
+ # a description line per article (date, title of the article and
+ # CSS description tooltips on mouse over)
+ html += article["article_date"].ctime() + " - " + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s<span class="classic">%s</span></a><br />\n""" % \
+ (feed["feed_id"], article["article_id"], article["article_title"][:150], description)
+
+ if nb_unread == self.mongo.nb_unread_articles(feed["feed_id"]):
+ html += """<br />\n<a href="/mark_as_read/Feed:%s">Mark all articles from this feed as read</a>\n""" % \
+ (feed["feed_id"],)
+ html += """<hr />\n<a href="/mark_as_read/">Mark articles as read</a>\n"""
+
+ # List unread articles of a feed
+ else:
+ try:
+ feed = self.mongo.get_collection(feed_id)
+ except:
+ self.error_page("This feed do not exists.")
+ html += """<h1>Unread article(s) of the feed <a href="/articles/%s">%s</a></h1>
+ <br />""" % (feed_id, feed["feed_title"])
+
+ # For all unread article of the feed.
+ for article in self.mongo.get_articles_from_collection(feed_id, condition=("article_readed", False)):
+ # descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content[:500].split(' ')[:-1])
+ else:
+ description = "No description."
+
+ # a description line per article (date, title of the article and
+ # CSS description tooltips on mouse over)
+ html += article["article_date"].ctime() + " - " + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s<span class="classic">%s</span></a><br />\n""" % \
+ (feed_id, article["article_id"], article["article_title"][:150], description)
+
+ html += """<hr />\n<a href="/mark_as_read/Feed:%s">Mark all as read</a>""" % (feed_id,)
+ # No unread article
+ else:
+ html += '<h1>No unread article(s)</h1>\n<br />\n<a href="/fetch/">Why not check for news?</a>'
+ html += """\n<h4><a href="/">All feeds</a></h4>"""
+ html += "<hr />\n"
+ html += htmlfooter
+ return html
+
+ unread.exposed = True
+
+
+ def history(self, query="all", m=""):
+ """
+ This page enables to browse articles chronologically.
+ """
+ feeds = self.mongo.get_all_collections()
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">\n"""
+
+ # Get the date from the tag cloud
+ # Format: /history/?query=year:2011-month:06 to get the
+ # list of articles of June, 2011.
+ if m != "":
+ query = """year:%s-month:%s""" % tuple(m.split('-'))
+
+ if query == "all":
+ html += "<h1>Search with tags cloud</h1>\n"
+ html += "<h4>Choose a year</h4></br >\n"
+ if "year" in query:
+ the_year = query.split('-')[0].split(':')[1]
+ if "month" not in query:
+ html += "<h1>Choose a month for " + the_year + "</h1></br >\n"
+ if "month" in query:
+ the_month = query.split('-')[1].split(':')[1]
+ html += "<h1>Articles of "+ calendar.month_name[int(the_month)] + \
+ ", "+ the_year +".</h1><br />\n"
+
+ timeline = Counter()
+ for feed in feeds:
+ new_feed_section = True
+ for article in self.mongo.get_articles_from_collection(feed["feed_id"]):
+
+ if query == "all":
+ timeline[str(article["article_date"]).split(' ')[0].split('-')[0]] += 1
+
+ elif query[:4] == "year":
+
+ if str(article["article_date"]).split(' ')[0].split('-')[0] == the_year:
+ timeline[str(article["article_date"]).split(' ')[0].split('-')[1]] += 1
+
+ if "month" in query:
+ if str(article["article_date"]).split(' ')[0].split('-')[1] == the_month:
+ if article["article_readed"] == False:
+ # not readed articles are in bold
+ not_read_begin, not_read_end = "<b>", "</b>"
+ else:
+ not_read_begin, not_read_end = "", ""
+
+ if article["article_like"] == True:
+ like = """ <img src="/img/heart.png" title="I like this article!" />"""
+ else:
+ like = ""
+ # Descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content[:500].split(' ')[:-1])
+ else:
+ description = "No description."
+ # Title of the article
+ article_title = article["article_title"]
+ if len(article_title) >= 110:
+ article_title = article_title[:110] + " ..."
+
+ if new_feed_section is True:
+ new_feed_section = False
+ html += """<h2><a name="%s"><a href="%s" rel="noreferrer"
+ target="_blank">%s</a></a><a href="%s" rel="noreferrer"
+ target="_blank"><img src="%s" width="28" height="28" /></a></h2>\n""" % \
+ (feed["feed_id"], feed["feed_link"], feed["feed_title"], feed["feed_link"], feed["feed_image"])
+
+ html += article["article_date"].strftime("%a %d (%H:%M:%S) ") + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s%s%s<span class="classic">%s</span></a>""" % \
+ (feed["feed_id"], article["article_id"], not_read_begin, \
+ article_title, not_read_end, description) + like + "<br />\n"
+ if query == "all":
+ query_string = "year"
+ elif "year" in query:
+ query_string = "year:" + the_year + "-month"
+ if "month" not in query:
+ html += '<div style="width: 35%; overflow:hidden; text-align: justify">' + \
+ utils.tag_cloud([(elem, timeline[elem]) for elem in timeline.keys()], query_string) + '</div>'
+ html += '<br /><br /><h1>Search with a month+year picker</h1>\n'
+ html += '<form>\n\t<input name="m" type="month">\n\t<input type="submit" value="Go">\n</form>'
+ html += '<hr />'
+ html += htmlfooter
+ return html
+
+ history.exposed = True
+
+
+ def plain_text(self, target):
+ """
+ Display an article in plain text (without HTML tags).
+ """
+ try:
+ feed_id, article_id = target.split(':')
+ feed = self.mongo.get_collection(feed_id)
+ article = self.mongo.get_article(feed_id, article_id)
+ except:
+ return self.error_page("Bad URL. This article do not exists.")
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ html += """<h1><i>%s</i> from <a href="/articles/%s">%s</a></h1>\n<br />\n"""% \
+ (article["article_title"], feed_id, feed["feed_title"])
+ description = utils.clear_string(article["article_content"])
+ if description:
+ html += description
+ else:
+ html += "No description available."
+ html += "\n<hr />\n" + htmlfooter
+ return html
+
+ plain_text.exposed = True
+
+
+ def error_page(self, message):
+ """
+ Display a message (bad feed id, bad article id, etc.)
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ html += """%s""" % message
+ html += "\n<hr />\n" + htmlfooter
+ return html
+
+ error_page.exposed = True
+
+
+ def mark_as_read(self, target=""):
+ """
+ Mark one (or more) article(s) as read by setting the value of the field
+ 'article_readed' of the MongoDB database to 'True'.
+ """
+ param, _, identifiant = target.partition(':')
+
+ # Mark all articles as read.
+ if param == "":
+ self.mongo.mark_as_read(True, None, None)
+ # Mark all articles from a feed as read.
+ elif param == "Feed" or param == "Feed_FromMainPage":
+ self.mongo.mark_as_read(True, identifiant, None)
+ # Mark an article as read.
+ elif param == "Article":
+ self.mongo.mark_as_read(True, identifiant.split(':')[1], identifiant.split(':')[0])
+ if param == "" or param == "Feed_FromMainPage":
+ return self.index()
+ elif param == "Feed":
+ return self.articles(identifiant)
+
+ mark_as_read.exposed = True
+
+
+ def notifications(self):
+ """
+ List all active e-mail notifications.
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ feeds = self.mongo.get_all_collections(condition=("mail",True))
+ if feeds != []:
+ html += "<h1>You are receiving e-mails for the following feeds:</h1>\n"
+ for feed in feeds:
+ html += """\t<a href="/articles/%s">%s</a> - <a href="/mail_notification/0:%s">Stop</a><br />\n""" % \
+ (feed["feed_id"], feed["feed_title"], feed["feed_id"])
+ else:
+ html += "<p>No active notifications.<p>\n"
+ html += """<p>Notifications are sent to: <a href="mail:%s">%s</a></p>""" % \
+ (utils.mail_to, utils.mail_to)
+ html += "\n<hr />\n" + htmlfooter
+ return html
+
+ notifications.exposed = True
+
+
+ def mail_notification(self, param):
+ """
+ Enable or disable to notifications of news for a feed.
+ """
+ try:
+ action, feed_id = param.split(':')
+ feed = self.feeds[feed_id]
+ except:
+ return self.error_page("Bad URL. This feed do not exists.")
+
+ return self.index()
+
+ mail_notification.exposed = True
+
+
+ def like(self, param):
+ """
+ Mark or unmark an article as favorites.
+ """
+ try:
+ like, feed_id, article_id = param.split(':')
+ articles = self.mongo.get_article(feed_id, article_id)
+ except:
+ return self.error_page("Bad URL. This article do not exists.")
+ self.mongo.like_article("1"==like, feed_id, article_id)
+ return self.article(feed_id+":"+article_id)
+
+ like.exposed = True
+
+
+ def favorites(self):
+ """
+ List of favorites articles
+ """
+ feeds = self.mongo.get_all_collections()
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ html += "<h1>Your favorites articles</h1>"
+ for feed in feeds:
+ new_feed_section = True
+ for article in self.mongo.get_articles_from_collection(feed["feed_id"]):
+ if article["article_like"] == True:
+ if new_feed_section is True:
+ new_feed_section = False
+ html += """<h2><a name="%s"><a href="%s" rel="noreferrer"target="_blank">%s</a></a><a href="%s" rel="noreferrer" target="_blank"><img src="%s" width="28" height="28" /></a></h2>\n""" % \
+ (feed["feed_id"], feed["feed_link"], feed["feed_title"], feed["feed_link"], feed["feed_image"])
+
+ # descrition for the CSS ToolTips
+ article_content = utils.clear_string(article["article_content"])
+ if article_content:
+ description = " ".join(article_content[:500].split(' ')[:-1])
+ else:
+ description = "No description."
+
+ # a description line per article (date, title of the article and
+ # CSS description tooltips on mouse over)
+ html += article["article_date"].ctime() + " - " + \
+ """<a class="tooltip" href="/article/%s:%s" rel="noreferrer" target="_blank">%s<span class="classic">%s</span></a><br />\n""" % \
+ (feed["feed_id"], article["article_id"], article["article_title"][:150], description)
+ html += "<hr />\n"
+ html += htmlfooter
+ return html
+
+ favorites.exposed = True
+
+
+ def add_feed(self, url):
+ """
+ Add a new feed with the URL of a page.
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ # search the feed in the HTML page with BeautifulSoup
+ feed_url = utils.search_feed(url)
+ if feed_url is None:
+ return self.error_page("Impossible to find a feed at this URL.")
+ # if a feed exists
+ else:
+ result = utils.add_feed(feed_url)
+ # if the feed is not in the file feed.lst
+ if result is False:
+ html += "<p>You are already following this feed!</p>"
+ else:
+ html += """<p>Feed added. You can now <a href="/fetch/">fetch your feeds</a>.</p>"""
+ html += """\n<br />\n<a href="/management/">Back to the management page.</a><br />\n"""
+ html += "<hr />\n"
+ html += htmlfooter
+ return html
+
+ add_feed.exposed = True
+
+
+ def remove_feed(self, feed_id):
+ """
+ Remove a feed from the file feed.lst and from the MongoDB database.
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+
+ feed = self.mongo.get_collection(feed_id)
+ self.mongo.delete_feed(feed_id)
+ utils.remove_feed(feed["feed_link"])
+
+ html += """<p>All articles from the feed <i>%s</i> are now removed from the base.</p><br />""" % \
+ (feed["feed_title"],)
+ html += """<a href="/management/">Back to the management page.</a><br />\n"""
+ html += "<hr />\n"
+ html += htmlfooter
+ return html
+
+ remove_feed.exposed = True
+
+
+ def change_feed_url(self, new_feed_url, old_feed_url):
+ """
+ Enables to change the URL of a feed already present in the database.
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ utils.change_feed_url(old_feed_url, new_feed_url)
+ html += "<p>The URL of the feed has been changed.</p>"
+ html += "<hr />\n"
+ html += htmlfooter
+ return html
+
+ change_feed_url.exposed = True
+
+ def change_feed_name(self, feed_url, new_feed_name):
+ """
+ Enables to change the name of a feed.
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ utils.change_feed_name(feed_url, new_feed_name)
+ html += "<p>The name of the feed has been changed.</p>"
+ html += "<hr />\n"
+ html += htmlfooter
+ return html
+
+ change_feed_name.exposed = True
+
+ def change_feed_logo(self, feed_url, new_feed_logo):
+ """
+ Enables to change the name of a feed.
+ """
+ html = htmlheader()
+ html += htmlnav
+ html += """<div class="left inner">"""
+ utils.change_feed_logo(feed_url, new_feed_logo)
+ html += "<p>The logo of the feed has been changed.</p>"
+ html += "<hr />\n"
+ html += htmlfooter
+ return html
+
+ change_feed_logo.exposed = True
+
+
+ def set_max_articles(self, max_nb_articles=1):
+ """
+ Enables to set the maximum of articles to be loaded per feed from
+ the data base.
+ """
+ if max_nb_articles < -1 or max_nb_articles == 0:
+ max_nb_articles = 1
+ utils.MAX_NB_ARTICLES = int(max_nb_articles)
+ return self.management()
+
+ set_max_articles.exposed = True
+
+
+ def delete_article(self, param):
+ """
+ Delete an article.
+ """
+ try:
+ feed_id, article_id = param.split(':')
+ self.mongo.delete_article(feed_id, article_id)
+ except:
+ return self.error_page("Bad URL. This article do not exists.")
+
+ return self.index()
+
+ delete_article.exposed = True
+
+
+ def drop_base(self):
+ """
+ Delete all articles.
+ """
+ utils.drop_base()
+ return self.management()
+
+ drop_base.exposed = True
+
+
+ def export(self, export_method):
+ """
+ Export articles currently loaded from the MongoDB database with
+ the appropriate function of the 'export' module.
+ """
+ try:
+ getattr(export, export_method)(self.feeds)
+ except Exception, e:
+ return self.error_page(e)
+ return self.management()
+
+ export.exposed = True
+
+
+ def epub(self, param):
+ """
+ Export an article to EPUB.
+ """
+ try:
+ from epub import ez_epub
+ except Exception, e:
+ return self.error_page(e)
+ try:
+ feed_id, article_id = param.split(':')
+ except:
+ return self.error_page("Bad URL.")
+ try:
+ feed = self.feeds[feed_id]
+ article = feed.articles[article_id]
+ except:
+ self.error_page("This article do not exists.")
+ try:
+ folder = utils.path + "/var/export/epub/"
+ os.makedirs(folder)
+ except OSError:
+ # directories already exists (not a problem)
+ pass
+ section = ez_epub.Section()
+ section.title = article.article_title.decode('utf-8')
+ section.paragraphs = [utils.clear_string(article.article_description).decode('utf-8')]
+ ez_epub.makeBook(article.article_title.decode('utf-8'), [feed.feed_title.decode('utf-8')], [section], \
+ os.path.normpath(folder) + "article.epub", lang='en-US', cover=None)
+ return self.article(param)
+
+ epub.exposed = True
+
+
+if __name__ == '__main__':
+ # Point of entry in execution mode
+ print "Launching pyAggr3g470r..."
+
+ root = Root()
+ root.favicon_ico = cherrypy.tools.staticfile.handler(filename=os.path.join(utils.path + "/img/favicon.png"))
+ cherrypy.config.update({ 'server.socket_port': 12556, 'server.socket_host': "0.0.0.0"})
+ cherrypy.config.update({'error_page.404': error_page_404})
+ _cp_config = {'request.error_response': handle_error}
+
+ cherrypy.quickstart(root, "/" ,config=utils.path + "/cfg/cherrypy.cfg") \ No newline at end of file
diff --git a/source/sqlite2mongo.py b/source/sqlite2mongo.py
new file mode 100644
index 00000000..633fb8f9
--- /dev/null
+++ b/source/sqlite2mongo.py
@@ -0,0 +1,78 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import hashlib
+import sqlite3
+import mongodb
+
+import utils
+
+from datetime import datetime
+
+SQLITE_BASE = "./var/feed.db"
+
+
+def sqlite2mongo():
+ """
+ Load feeds and articles in a dictionary.
+ """
+ mongo = mongodb.Articles()
+ list_of_feeds = []
+ list_of_articles = []
+
+ try:
+ conn = sqlite3.connect(SQLITE_BASE, isolation_level = None)
+ c = conn.cursor()
+ list_of_feeds = c.execute("SELECT * FROM feeds").fetchall()
+ except:
+ pass
+
+ if list_of_feeds != []:
+ # Walk through the list of feeds
+ for feed in list_of_feeds:
+ try:
+ list_of_articles = c.execute(\
+ "SELECT * FROM articles WHERE feed_link='" + \
+ feed[2] + "'").fetchall()
+ except:
+ continue
+ sha1_hash = hashlib.sha1()
+ sha1_hash.update(feed[2].encode('utf-8'))
+ feed_id = sha1_hash.hexdigest()
+
+ new_collection = {"feed_id" : feed_id.encode('utf-8'), \
+ "type": 0, \
+ "feed_image" : feed[3].encode('utf-8'), \
+ "feed_title" : feed[0].encode('utf-8'), \
+ "feed_link" : feed[2].encode('utf-8'), \
+ "site_link" : feed[1].encode('utf-8'), \
+ "mail" : feed[4]=="1"}
+
+ mongo.add_collection(new_collection)
+
+ if list_of_articles != []:
+ # Walk through the list of articles for the current feed.
+ articles = []
+ for article in list_of_articles:
+ sha1_hash = hashlib.sha1()
+ sha1_hash.update(article[2].encode('utf-8'))
+ article_id = sha1_hash.hexdigest()
+
+ article = {"article_id": article_id.encode('utf-8'), \
+ "type":1, \
+ "article_date": utils.string_to_datetime(article[0]), \
+ "article_link": article[2].encode('utf-8'), \
+ "article_title": article[1].encode('utf-8'), \
+ "article_content": article[3].encode('utf-8'), \
+ "article_readed": article[4]=="1", \
+ "article_like": article[6]=="1" \
+ }
+
+ articles.append(article)
+
+ mongo.add_articles(articles, feed_id)
+
+ c.close()
+
+if __name__ == "__main__":
+ sqlite2mongo() \ No newline at end of file
diff --git a/source/utils.py b/source/utils.py
new file mode 100755
index 00000000..c23b8794
--- /dev/null
+++ b/source/utils.py
@@ -0,0 +1,351 @@
+#! /usr/bin/env python
+#-*- coding: utf-8 -*-
+
+# pyAggr3g470r - A Web based news aggregator.
+# Copyright (C) 2010 Cédric Bonhomme - http://cedricbonhomme.org/
+#
+# For more information : http://bitbucket.org/cedricbonhomme/pyaggr3g470r/
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>
+
+__author__ = "Cedric Bonhomme"
+__version__ = "$Revision: 1.2 $"
+__date__ = "$Date: 2010/12/07 $"
+__revision__ = "$Date: 2011/04/15 $"
+__copyright__ = "Copyright (c) Cedric Bonhomme"
+__license__ = "GPLv3"
+
+#
+# This file provides functions used for:
+# - the database management;
+# - generation of tags cloud;
+# - HTML processing;
+# - mail notifications.
+#
+
+import re
+import hashlib
+import sqlite3
+import operator
+import urlparse
+import calendar
+import unicodedata
+import htmlentitydefs
+
+import smtplib
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
+
+import urllib2
+import BaseHTTPServer
+from BeautifulSoup import BeautifulSoup
+
+from datetime import datetime
+from string import punctuation
+from collections import Counter
+from collections import OrderedDict
+
+from StringIO import StringIO
+
+import threading
+LOCKER = threading.Lock()
+
+import os
+import ConfigParser
+# load the configuration
+config = ConfigParser.RawConfigParser()
+try:
+ config.read("./cfg/pyAggr3g470r.cfg")
+except:
+ config.read("./cfg/pyAggr3g470r.cfg-sample")
+path = os.path.abspath(".")
+
+MONGODB_ADDRESS = config.get('MongoDB', 'address')
+MONGODB_PORT = int(config.get('MongoDB', 'port'))
+MONGODB_USER = config.get('MongoDB', 'user')
+MONGODB_PASSWORD = config.get('MongoDB', 'password')
+
+MAX_NB_ARTICLES = int(config.get('global', 'max_nb_articles'))
+
+mail_from = config.get('mail','mail_from')
+mail_to = config.get('mail','mail_to')
+smtp_server = config.get('mail','smtp')
+username = config.get('mail','username')
+password = config.get('mail','password')
+
+DIASPORA_POD = config.get('misc', 'diaspora_pod')
+
+# regular expression to chech URL
+url_finders = [ \
+ re.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+)(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\),\\\"]"), \
+ re.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+)(:[0-9]*)?"), \
+ re.compile("(~/|/|\\./)([-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]|\\\\)+"), \
+ re.compile("'\\<((mailto:)|)[-A-Za-z0-9\\.]+@[-A-Za-z0-9\\.]+"), \
+]
+
+def detect_url_errors(list_of_urls):
+ """
+ Detect URL errors.
+ Return a list of error(s).
+ """
+ errors = []
+ for url in list_of_urls:
+ req = urllib2.Request(url)
+ try:
+ urllib2.urlopen(req)
+ except urllib2.HTTPError, e:
+ # server couldn't fulfill the request
+ errors.append((url, e.code, \
+ BaseHTTPServer.BaseHTTPRequestHandler.responses[e.code][1]))
+ except urllib2.URLError, e:
+ # failed to reach the server
+ errors.append((url, e.reason.errno ,e.reason.strerror))
+ return errors
+
+def clear_string(data):
+ """
+ Clear a string by removing HTML tags, HTML special caracters
+ and consecutive white spaces (more that one).
+ """
+ p = re.compile(r'<[^<]*?/?>') # HTML tags
+ q = re.compile(r'\s') # consecutive white spaces
+ return p.sub('', q.sub(' ', data))
+
+def unescape(text):
+ """
+ Removes HTML or XML character references and entities from a text string.
+ """
+ def fixup(m):
+ text = m.group(0)
+ if text[:2] == "&#":
+ # character reference
+ try:
+ if text[:3] == "&#x":
+ return unichr(int(text[3:-1], 16))
+ else:
+ return unichr(int(text[2:-1]))
+ except ValueError:
+ pass
+ else:
+ # named entity
+ try:
+ text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
+ except KeyError:
+ pass
+ return text # leave as is
+ return re.sub("&#?\w+;", fixup, text)
+
+def not_combining(char):
+ return unicodedata.category(char) != 'Mn'
+
+def strip_accents(text, encoding):
+ """
+ Strip accents.
+
+ >>> print strip_accents("déjà", "utf-8")
+ deja
+ """
+ unicode_text= unicodedata.normalize('NFD', text.decode(encoding))
+ return filter(not_combining, unicode_text).encode(encoding)
+
+def normalize_filename(name):
+ """
+ Normalize a file name.
+ """
+ file_name = re.sub("[,'!?|&]", "", name)
+ file_name = re.sub("[\s.]", "_", file_name)
+ file_name = file_name.strip('_')
+ file_name = file_name.strip('.')
+ file_name = strip_accents(file_name, "utf-8")
+ return os.path.normpath(file_name)
+
+def top_words(articles, n=10, size=5):
+ """
+ Return the n most frequent words in a list.
+ """
+ words = Counter()
+ wordre = re.compile(r'\b\w{%s,}\b' % size, re.I)
+ for article in articles:
+ for word in wordre.findall(clear_string(article["article_content"])):
+ words[word.lower()] += 1
+ return words.most_common(n)
+
+def tag_cloud(tags, query="word_count"):
+ """
+ Generates a tags cloud.
+ """
+ tags.sort(key=operator.itemgetter(0))
+ if query == "word_count":
+ # tags cloud from the management page
+ return ' '.join([('<font size=%d><a href="/search/?query=%s" title="Count: %s">%s</a></font>\n' % \
+ (min(1 + count * 7 / max([tag[1] for tag in tags]), 7), word, count, word)) \
+ for (word, count) in tags])
+ if query == "year":
+ # tags cloud for the history
+ return ' '.join([('<font size=%d><a href="/history/?query=%s:%s" title="Count: %s">%s</a></font>\n' % \
+ (min(1 + count * 7 / max([tag[1] for tag in tags]), 7), query, word, count, word)) \
+ for (word, count) in tags])
+ return ' '.join([('<font size=%d><a href="/history/?query=%s:%s" title="Count: %s">%s</a></font>\n' % \
+ (min(1 + count * 7 / max([tag[1] for tag in tags]), 7), query, word, count, calendar.month_name[int(word)])) \
+ for (word, count) in tags])
+
+def send_mail(mfrom, mto, feed_title, article_title, description):
+ """
+ Send the article via mail.
+ """
+ # Create the body of the message (a plain-text and an HTML version).
+ html = """<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n%s\n</body>\n</html>""" % \
+ (feed_title + ": " + article_title, description)
+ text = clear_string(description)
+
+ # Create message container - the correct MIME type is multipart/alternative.
+ msg = MIMEMultipart('alternative')
+ msg['Subject'] = '[pyAggr3g470r] ' + feed_title + ": " + article_title
+ msg['From'] = mfrom
+ msg['To'] = mto
+
+ # Record the MIME types of both parts - text/plain and text/html.
+ part1 = MIMEText(text, 'plain')
+ part2 = MIMEText(html, 'html')
+
+ # Attach parts into message container.
+ # According to RFC 2046, the last part of a multipart message, in this case
+ # the HTML message, is best and preferred.
+ msg.attach(part1)
+ msg.attach(part2)
+
+ # Send the message via local SMTP server.
+ s = smtplib.SMTP(smtp_server)
+ s.login(username, password)
+ # sendmail function takes 3 arguments: sender's address, recipient's address
+ # and message to send - here it is sent as one string.
+ s.sendmail(mfrom, mto, msg.as_string())
+ s.quit()
+
+def string_to_datetime(stringtime):
+ """
+ Convert a string to datetime.
+ """
+ date, time = stringtime.split(' ')
+ year, month, day = date.split('-')
+ hour, minute, second = time.split(':')
+ return datetime(year=int(year), month=int(month), day=int(day), \
+ hour=int(hour), minute=int(minute), second=int(second))
+
+def compare(stringtime1, stringtime2):
+ """
+ Compare two dates in the format 'yyyy-mm-dd hh:mm:ss'.
+ """
+ datetime1 = string_to_datetime(stringtime1)
+ datetime2 = string_to_datetime(stringtime2)
+ if datetime1 < datetime2:
+ return -1
+ elif datetime1 > datetime2:
+ return 1
+ return 0
+
+def add_feed(feed_url):
+ """
+ Add the URL feed_url in the file feed.lst.
+ """
+ if os.path.exists("./var/feed.lst"):
+ for line in open("./var/feed.lst", "r"):
+ if feed_url in line:
+ # if the feed is already in the file
+ return False
+ with open("./var/feed.lst", "a") as f:
+ f.write(feed_url + "\n")
+ return True
+
+def change_feed_url(old_feed_url, new_feed_url):
+ """
+ Change the URL of a feed given in parameter.
+ """
+ # Replace the URL in the text file
+ with open("./var/feed.lst", "r") as f:
+ lines = f.readlines()
+ try:
+ lines[lines.index(old_feed_url+"\n")] = new_feed_url + '\n'
+ except:
+ return
+ with open("./var/feed.lst", "w") as f:
+ f.write("\n".join(lines))
+
+ # Replace the URL in the data base.
+ try:
+ conn = sqlite3.connect(sqlite_base, isolation_level = None)
+ c = conn.cursor()
+ c.execute("UPDATE articles SET feed_link='" + new_feed_url + "' WHERE feed_link='" + old_feed_url +"'")
+ c.execute("UPDATE feeds SET feed_link='" + new_feed_url + "' WHERE feed_link='" + old_feed_url +"'")
+ conn.commit()
+ c.close()
+ except Exception, e:
+ print e
+
+def change_feed_name(feed_url, new_feed_name):
+ """
+ Change the name of a feed given in parameter.
+ """
+ try:
+ conn = sqlite3.connect(sqlite_base, isolation_level = None)
+ c = conn.cursor()
+ c.execute('UPDATE feeds SET feed_title="' + new_feed_name + '" WHERE feed_link="' + feed_url +'"')
+ conn.commit()
+ c.close()
+ except Exception, e:
+ print e
+
+def change_feed_logo(feed_url, new_feed_logo):
+ """
+ Change the logo of a feed given in parameter.
+ """
+ try:
+ conn = sqlite3.connect(sqlite_base, isolation_level = None)
+ c = conn.cursor()
+ c.execute('UPDATE feeds SET feed_image_link="' + new_feed_logo + '" WHERE feed_link="' + feed_url +'"')
+ conn.commit()
+ c.close()
+ except Exception, e:
+ print e
+
+def remove_feed(feed_url):
+ """
+ Remove a feed from the file feed.lst and from the SQLite base.
+ """
+ feeds = []
+ # Remove the URL from the file feed.lst
+ if os.path.exists("./var/feed.lst"):
+ for line in open("./var/feed.lst", "r"):
+ if feed_url not in line:
+ feeds.append(line.replace("\n", ""))
+ with open("./var/feed.lst", "w") as f:
+ f.write("\n".join(feeds) + "\n")
+
+def search_feed(url):
+ """
+ Search a feed in a HTML page.
+ """
+ soup = None
+ try:
+ page = urllib2.urlopen(url)
+ soup = BeautifulSoup(page)
+ except:
+ return None
+ feed_links = soup('link', type='application/atom+xml')
+ feed_links.extend(soup('link', type='application/rss+xml'))
+ for feed_link in feed_links:
+ if url not in feed_link['href']:
+ return urlparse.urljoin(url, feed_link['href'])
+ return feed_link['href']
+ return None \ No newline at end of file
diff --git a/source/var/feed.lst b/source/var/feed.lst
new file mode 100755
index 00000000..51cd1936
--- /dev/null
+++ b/source/var/feed.lst
@@ -0,0 +1,37 @@
+http://feeds2.feedburner.com/diveintomark/all
+http://www.foo.be/cgi-bin/wiki.pl?action=journal&tile=AdulauMessyDesk
+http://blog.cedricbonhomme.org/feed/
+http://bnjgat.fr/weblog/?feed/rss2
+http://standblog.org/blog/feed/atom
+http://www.haypocalc.com/blog/rss.php
+http://linuxfr.org/news.atom
+http://rss.slashdot.org/Slashdot/slashdot
+http://theinvisiblethings.blogspot.com/feeds/posts/default
+http://torvalds-family.blogspot.com/feeds/posts/default
+http://www.python.org/channews.rdf
+http://www.kde.org/dotkdeorg.rdf
+http://feeds.feedburner.com/internetactu/bcmJ
+http://www.april.org/fr/rss.xml
+http://www.framablog.org/index.php/feed/atom
+http://tarekziade.wordpress.com/feed/
+http://formats-ouverts.org/rss.php
+http://lwn.net/headlines/newrss
+http://kernelnewbies.org/RecentChanges?action=rss_rc&ddiffs=1&unique=1
+http://www.kroah.com/log/index.rss
+http://www.lessentiel.lu/rss/news.tmpl
+http://www.jeffersonswheel.org/?feed=rss2
+http://www.laquadrature.net/en/rss.xml
+http://static.fsf.org/fsforg/rss/blogs.xml
+http://esr.ibiblio.org/?feed=rss2
+http://www.maitre-eolas.fr/feed/atom
+http://linuxfr.org/journaux.atom
+http://www.le-tigre.net/spip.php?page=backend
+http://www.schneier.com/blog/index.rdf
+http://www.handcrafted-games.com/index.php?feed/atom
+http://python-history.blogspot.com/feeds/posts/default
+http://www.haypocalc.com/wordpress/feed
+http://www.crypto.com/blog/rss10.xml
+http://spaf.wordpress.com/feed/
+http://neopythonic.blogspot.com/feeds/posts/default
+http://www.quuxlabs.com/feed/
+http://etbe.coker.com.au/feed/
bgstack15