Skip to content
This repository has been archived by the owner on May 9, 2023. It is now read-only.

Unit tests, RSS Views, Item Revisions Trigger #14

Merged
merged 28 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9cd60e1
RSS feeds support into Wikipedia IFTTT
xSavitar Mar 29, 2016
979c15f
Building RSS/XML for Article of the Day
xSavitar Apr 7, 2016
691b0d2
Impemented browser GET request for IFTTT RSS
xSavitar Apr 9, 2016
fbaf065
Changes to the XML template for AotD
xSavitar Apr 11, 2016
f4bf87a
Fixes to XML tag for media_url
xSavitar Apr 11, 2016
d35ed6a
Changed XML tags such that a feed reader(Liferea in Ubuntu) can read …
xSavitar Apr 11, 2016
cb5712e
Linking the list of RSS feeds to their RSS
xSavitar Apr 11, 2016
3f96a00
Removing the IFTTT-Channel-Key
xSavitar Apr 11, 2016
1fe6c01
Adding more templates for RSS feeds
xSavitar Apr 11, 2016
21980a2
Adding more RSS/XML Templates
xSavitar Apr 27, 2016
9681f9a
Integration of Travis-CI
xSavitar May 7, 2016
5208d7a
Adding verbose testing mode by nosetests
xSavitar May 7, 2016
a4a9568
Test suite for Wikipedia triggers
xSavitar May 7, 2016
55036ba
Unit tests
xSavitar May 7, 2016
b88b9b5
More on Travics-CI config and RSS View
xSavitar May 7, 2016
d424ee0
Working on Test Suite configs
xSavitar May 8, 2016
5070fa6
Docs updates
xSavitar May 9, 2016
005c111
Unit test for all trigger
xSavitar May 13, 2016
c3db934
Resolved conflicts from merge
xSavitar May 15, 2016
29318d7
Fixed Typo
xSavitar May 15, 2016
aec0bb0
Remove unwanted method
xSavitar May 15, 2016
0ae3fed
Bug fixes to test more triggers
xSavitar May 19, 2016
5d4b3ce
Fixing errors
xSavitar May 30, 2016
7c2ee1c
Removed IRC channel and changes to feeds.html
xSavitar May 30, 2016
74b60b9
Item Revisions Trigger
xSavitar Jun 5, 2016
1bd3e5c
RSS View for Item Revision
xSavitar Jun 9, 2016
53edaf0
Code clean up and wrap up
xSavitar Jun 10, 2016
21f35dc
Resolving conflicts
xSavitar Jun 11, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Programming language in concern, in this
# case python.
language: python

# Version of python used in the code
python:
- "2.7"

# command to install flask dependencies
install:
- pip install -r requirements.txt

# command to run tests
script: nosetests -v

# travis notification to irc
notifications:
irc:
channels:
- "irc.freenode.net#wikidata-feed"
on_success: always # [always|never|change] # default: change
on_failure: always # [always|never|change] # default: always
template:
- "%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message}"
- "Change view : %{compare_url}"
- "Build details : %{build_url}"
use_notice: true
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Wikipedia channel for IFTTT
# Wikipedia and Wikidata channels for IFTTT

An [IFTTT](https://ifttt.com/recipes) channel built for [Wikimedia Tool Labs](http://tools.wmflabs.org/).

Expand All @@ -13,6 +13,7 @@ It currently supports the following triggers:
- Updates from user
- Page added to category
- Page updated in category
- Updates to an item

# [WIP] Deploying to Wikimedia Labs

Expand Down Expand Up @@ -63,11 +64,11 @@ Disconnecting from madhuvishy@ifttt-staging.ifttt.eqiad.wmflabs... done.

* To restart the service: `fab <staging|production> restart_ifttt`


# License

Copyright 2015 Ori Livneh <ori@wikimedia.org>,
Stephen LaPorte <stephen.laporte@gmail.com>
Stephen LaPorte <stephen.laporte@gmail.com>,
Alangi Derick <alangiderick@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from ifttt import app

# if __name__ == '__main__':
# app.debug = True
# app.run(debug=True)
if __name__ == '__main__':
app.debug = True
app.run(debug=True)
5 changes: 3 additions & 2 deletions ifttt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copyright 2015 Ori Livneh <ori@wikimedia.org>,
Stephen LaPorte <stephen.laporte@gmail.com>
Stephen LaPorte <stephen.laporte@gmail.com>,
Alangi Derick <alangiderick@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -24,5 +25,5 @@
reload(sys)
sys.setdefaultencoding('utf-8')


from .core import app
from flask import Flask
29 changes: 24 additions & 5 deletions ifttt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copyright 2015 Ori Livneh <ori@wikimedia.org>,
Stephen LaPorte <stephen.laporte@gmail.com>
Stephen LaPorte <stephen.laporte@gmail.com>,
Alangi Derick <alangiderick@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,7 +22,7 @@
"""

import flask
from flask import request
from flask import request, render_template, g

from .utils import snake_case
from .triggers import (ArticleOfTheDay,
Expand All @@ -32,7 +33,8 @@
NewArticle,
NewHashtag,
NewCategoryMember,
CategoryMemberRevisions)
CategoryMemberRevisions,
ItemRevisions)

import logging
LOG_FILE = 'ifttt.log'
Expand All @@ -50,11 +52,12 @@
NewArticle,
NewHashtag,
NewCategoryMember,
CategoryMemberRevisions]
CategoryMemberRevisions,
ItemRevisions]

app = flask.Flask(__name__)
# Load default config first
app.config.from_pyfile('../default.cfg', silent=True)
# app.config.from_pyfile('../default.cfg', silent=True)
# Override defaults if ifttt.cfg is present
app.config.from_pyfile('../ifttt.cfg', silent=True)

Expand All @@ -78,6 +81,8 @@ def force_content_type(response):
"""RFC 4627 stipulates that 'application/json' takes no charset parameter,
but IFTTT expects one anyway. We have to twist Flask's arm to get it to
break the spec."""
if g.get('skip_after_request'):
return response
response.headers['Content-Type'] = 'application/json; charset=utf-8'
return response

Expand All @@ -103,6 +108,20 @@ def test_setup():
return flask.jsonify(data=ret)


@app.route('/ifttt/v1/rss-feeds')
def feeds():
"""Returns a list of all feeds(triggers) for Wikipedia IFTTT."""
feeds = {'samples': {'feeds': {}}}
for feed in ALL_TRIGGERS:
feed_name = snake_case(feed.__name__)
feed_display_name = feed_name.replace("_", " ").capitalize()
if feed.default_fields:
feeds['samples']['feeds'][feed_display_name] = feed.default_fields

g.skip_after_request = True
return render_template('feeds.html', data=feeds)


@app.route('/ifttt/v1/status')
def status():
"""Return HTTP 200 and an empty body, as required by the IFTTT spec."""
Expand Down
67 changes: 67 additions & 0 deletions ifttt/ifttt-tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
"""
Wikipedia channel for IFTTT
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copyright 2015 Ori Livneh <ori@wikimedia.org>
Stephen LaPorte <stephen.laporte@gmail.com>
Alangi Derick <alangiderick@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

"""

import core, json, unittest

from .utils import snake_case

# Import all triggers in the app
from .triggers import (ArticleOfTheDay,
PictureOfTheDay,
WordOfTheDay,
ArticleRevisions,
UserRevisions,
NewArticle,
NewHashtag,
NewCategoryMember,
CategoryMemberRevisions,
ItemRevisions)

# A list of triggers to be tested
ALL_TRIGGERS = [ArticleOfTheDay,
PictureOfTheDay,
WordOfTheDay,
NewArticle,
ItemRevisions,
ArticleRevisions,
UserRevisions]

app = core.app.test_client()

def check_response(test_trigger):
"""Checks the response to see if the data property of the trigger
is greater than 3 after the request."""
RESP_TEST_VALUE = 3

resp = app.post('/ifttt/v1/triggers/%s' % test_trigger)

results = json.loads(resp.data)
assert len(results['data']) >= RESP_TEST_VALUE

# Routine to test the triggers one after the other
def test_for_triggers():
for trigger in ALL_TRIGGERS:
test_trigger = getattr(trigger, 'url_pattern', None)
if not test_trigger:
test_trigger = snake_case(trigger.__name__)
yield check_response, test_trigger
Binary file added ifttt/static/rss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions ifttt/templates/article_of_the_day.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Article of the Day feeds</title>
<description>List of articles of the day for Wikipedia.</description>

<language>en-us</language>
{% for feeds in data %}
<item>
<pubDate>{{feeds.created_at}}</pubDate>
<guid>{{feeds.entry_id}}</guid>
<image>
<url>{{feeds.media_url}}</url>
</image>
<description>{{feeds.summary}}</description>
<title>{{feeds.title}}</title>
<link>{{feeds.url}}</link>
</item>
{% endfor %}
</channel>
</rss>
23 changes: 23 additions & 0 deletions ifttt/templates/article_revisions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Article Revisions feeds</title>
<description>List of an article revisions for Wikipedia.</description>

<language>en-us</language>
{% for feeds in data %}
<item>
<comment>{{feeds.comment}}</comment>
<pubDate>{{feeds.created_at}}</pubDate>
<date>{{feeds.date}}</date>
<image>
<url>{{feeds.media_url}}</url>
</image>
<size>{{feeds.size}}</size>
<title>{{feeds.title}}</title>
<link>{{feeds.url}}</link>
<user>{{feeds.user}}</user>
</item>
{% endfor %}
</channel>
</rss>
30 changes: 30 additions & 0 deletions ifttt/templates/feeds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>Wikipedia Feeds</title>
</head>
<body>

<h1>Wikipedia RSS feeds for IFTTT</h1>
<ul>
{% for feed in data.samples.feeds %}
<li>{{ feed }}&nbsp;&nbsp;

{% if feed == "User revisions" %}
<a href="http://localhost:5000/ifttt/v1/triggers/{{feed.replace(" ","_").lower()}}?lang=en&user=Alangi_derick"><img src="{{url_for('static', filename='rss.png')}}" width="20px" height="20px"></a>

{% elif feed == "Article revisions" %}
<a href="http://localhost:5000/ifttt/v1/triggers/{{feed.replace(" ","_").lower()}}?lang=en&title=Coffee"><img src="{{url_for('static', filename='rss.png')}}" width="20px" height="20px"></a>

{% elif feed == "Item revisions" %}
<a href="http://localhost:5000/ifttt/v1/triggers/{{feed.replace(" ","_").lower()}}?lang=en&itemid=Q12345"><img src="{{url_for('static', filename='rss.png')}}" width="20px" height="20px"></a>

{% else %}
<a href="http://localhost:5000/ifttt/v1/triggers/{{feed.replace(" ","_").lower()}}?lang=en"><img src="{{url_for('static', filename='rss.png')}}" width="20px" height="20px"></a>
{% endif %}
</li><br />
{% endfor %}
</ul>

</body>
</html>
23 changes: 23 additions & 0 deletions ifttt/templates/item_revisions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Wikidata Item revisions feed</title>
<description>List of a Wikidata item revisions.</description>

<language>en-us</language>
{% for feeds in data %}
<item>
<comment>{{feeds.comment}}</comment>
<pubDate>{{feeds.created_at}}</pubDate>
<date>{{feeds.date}}</date>
<image>
<url>{{feeds.media_url}}</url>
</image>
<description>Size: {{feeds.size}}</description>
<url>{{feeds.url}}</url>
<title>{{feeds.item}}</title>
<guid>{{feeds.user}}</guid>
</item>
{% endfor %}
</channel>
</rss>
20 changes: 20 additions & 0 deletions ifttt/templates/new_article.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>New article feeds</title>
<description>List New articles for Wikipedia.</description>

<language>en-us</language>
{% for feeds in data %}
<item>
<comment>{{feeds.comment}}</comment>
<pubDate>{{feeds.created_at}}</pubDate>
<date>{{feeds.date}}</date>
<size>{{feeds.size}}</size>
<title>{{feeds.title}}</title>
<url>{{feeds.url}}</url>
<user>{{feeds.user}}</user>
</item>
{% endfor %}
</channel>
</rss>
23 changes: 23 additions & 0 deletions ifttt/templates/user_revisions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>User revisions feed</title>
<description>List a user's revisions for Wikipedia.</description>

<language>en-us</language>
{% for feeds in data %}
<item>
<comment>{{feeds.comment}}</comment>
<pubDate>{{feeds.created_at}}</pubDate>
<date>{{feeds.date}}</date>
<image>
<url>{{feeds.media_url}}</url>
</image>
<description>Size: {{feeds.size}}</description>
<url>{{feeds.url}}</url>
<title>{{feeds.title}}</title>
<guid>{{feeds.user}}</guid>
</item>
{% endfor %}
</channel>
</rss>
18 changes: 18 additions & 0 deletions ifttt/templates/word_of_the_day.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Word of the Day feeds</title>
<description>List words of the day for Wikipedia.</description>

<language>en-us</language>
{% for feeds in data %}
<item>
<pubDate>{{feeds.created_at}}</pubDate>
<description>{{feeds.definition}}</description>
<guid>{{feeds.entry_id}}</guid>
<url>{{feeds.url}}</url>
<title>{{feeds.word}}</title>
</item>
{% endfor %}
</channel>
</rss>
Loading