Package: news-crawlers
News CrawlersContains various spiders which crawl websites for new content. If any new
content is found, users are alerted via email.InstallationInstall this application withpython -m pip install news_crawlersAfter installation, News Crawlers can be run from CLI, to view help you can write:python -m news_crawlers -hConfigurationNewsCrawlers's configuration is defined with anews_crawlers.yamlfile.Configuration file path can then be provided via CLI, like this:python -m news_crawlers -c {news_crawlers.yaml path}If path is not provided, application will search the file inconfigfolder (if it exists) and in the current working
directory.When spider is run, it will append any new items found in.nc_cachefolder. Location of that folder can be customized
with a --cache option, like thispython -m news_crawlers --cache {data path}If not specified, application will put cache todata/.nc_cache, relative to current working directory.Within the configuration file, there should be aspiderssegment, where spiders and their configurations are listed,
for example:spiders:
        bolha:
            notifications:
              email:
                email_user: "__env_EMAIL_USER"
                email_password: "__env_EMAIL_PASS"
                recipients: ['jost.prevc@gmail.com']
                message_body_format: "Query: {query}\nURL: {url}\nPrice: {price}\n"
              pushover:
                recipients: ['ukdwndomjog3swwos57umfydpsa2sk']
                send_separately: True
                message_body_format: "Query: {query}\nPrice: {price}\n"
            urls:
              'pet_prijateljev': https://www.bolha.com/?ctl=search_ads&keywords=pet+prijateljev
              'enid_blyton': https://www.bolha.com/?ctl=search_ads&keywords=enid%20blytonSpider name (for example "bolha", above), should match thenameattribute of a spider, defined in spiders.py.
Each spider should have anotificationsandurlssegment.notificationsdefines how user(s) will be notified on
any found changes when crawling the urls, defined inurlssegment.Note that prepending any configuration value with "__env_" will treat the subsequent string as an environment
variable and will attempt to obtain the value from environment variables. For example "__env_EMAIL_USER" will
be replaced with the value of "EMAIL_USER" environment variable. This can be useful to avoid storing secrets within the
configuration file.Crawling can also be set on a schedule, by adding a schedule segment to news_crawlers.yaml file:schedule:
    every: 15
    units: minutesSo the entirenews_crawlers.yamlfile should look like this:schedule:
    every: 15
    units: minutes
spiders:
    bolha:
        notifications:
          email:
            email_user: "__env_EMAIL_USER"
            email_password: "__env_EMAIL_PASS"
            recipients: ['jost.prevc@gmail.com']
            message_body_format: "Query: {query}\nURL: {url}\nPrice: {price}\n"
          pushover:
            recipients: ['ukdwndomjog3swwos57umfydpsa2sk']
            send_separately: True
            message_body_format: "Query: {query}\nPrice: {price}\n"
        urls:
          'pet_prijateljev': https://www.bolha.com/?ctl=search_ads&keywords=pet+prijateljev
          'enid_blyton': https://www.bolha.com/?ctl=search_ads&keywords=enid%20blytonNotification configurationNext, you should configure notification, which will alert you about any found news. Currently, there are two options -
Email via Gmail SMTP server or Pushover.Email configurationVisitgoogle app passwordsand generate a new app password for your account.Username and password can then be placed directly to configuration file or referenced via environment variables
(see instructions above).Pushover configurationPushoveris a platform which enables you to easily send and receive push notifications on your
smart device. To get it running, you will first need to create a user account. You can sign-up on
thislink. When sign-up is complete, you will receive a unique user token, which you
will have to copy and paste to your crawler configuration (see example configuration above). Any user that wants to
receive push notifications needs to create its own pushover username to receive their own user tokens, which will
be stored in crawler configuration.Next, you should register your crawler application on pushover. To do this, visitregistration siteand fill out the provided form. Once your application is registered, you will receive an API token. This token can then
be placed directly to configuration file or referenced via environment variables (see instructions above).To receive notifications, every user should download the Pushover app to the smart device on which they want to
receive push notifications. Once logged in, they will receive push notifications when any crawler finds news.AndroidAppStoreNote: Pushover trial version expires after 30 days. After that, you will need to create a one-time purchase with a cost
of 5$ to keep it working, seepricing.Running the crawlersRun the scraper by executing the following command on the project root:python -m news_crawlers scrapeYou can also run individual spiders withpython -m news_crawlers scrape -s {spider_name}This will run specified spider and then send a configured notifications if any
news are found.ContributionCheckoutCheckout this project withgit clone https://github.com/jprevc/news_crawlers.gitAdding new custom crawlersNew spiders need to be added to news_crawlers/spiders.py file. Spider is a class which must subclass Spider class.When crawling, crawler needs to yield all found items in a form of dictionary. Keys of each item need to correspond to
referenced values of "message_body_format" field within the configuration file.