This repository has been archived by the owner on May 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
369 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Core] | ||
Name = CSV Importer | ||
Module = csv_importer | ||
|
||
[Documentation] | ||
Author = Rio Lowry | ||
Version = 3.0.9999 | ||
Website = http://fosslc.org | ||
Description = CSV Importer plugin allows user to importfrom csv files when adding presentations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# freeseer - vga/presentation capture software | ||
# | ||
# Copyright (C) 2013 Free and Open Source Software Learning Centre | ||
# http://fosslc.org | ||
# | ||
# 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/>. | ||
|
||
# For support, questions, suggestions or any other inquiries, visit: | ||
# http://wiki.github.com/Freeseer/freeseer/ | ||
|
||
""" | ||
CSV Importer | ||
-------------- | ||
An import plugin for CSV files used when adding presentations | ||
@author: Rio Lowry | ||
""" | ||
|
||
import csv | ||
|
||
from freeseer.framework.presentation import Presentation | ||
from freeseer.framework.plugin import IImporter | ||
|
||
|
||
class CsvImporter(IImporter): | ||
"""CSV Importer plugin for Freeseer | ||
Provides functionality to import presentations from a CSV file | ||
""" | ||
|
||
name = "CSV Importer" | ||
os = ["linux", "linux2"] | ||
|
||
def get_presentations_list(self, fname): | ||
"""Returns list of dictionaries of all presentations in the csv file.""" | ||
presentations_list = [] | ||
|
||
try: | ||
with open(fname) as csv_file: | ||
reader = csv.DictReader(csv_file) | ||
for row in reader: | ||
talk = {'Title': unicode(row.get('Title', ''), 'utf-8'), | ||
'Speaker': unicode(row.get('Speaker', ''), 'utf-8'), | ||
'Abstract': unicode(row.get('Abstract', ''), 'utf-8'), # Description | ||
'Level': unicode(row.get('Level', ''), 'utf-8'), | ||
'Event': unicode(row.get('Event', ''), 'utf-8'), | ||
'Room': unicode(row.get('Room', ''), 'utf-8'), | ||
'Time': unicode(row.get('Time', ''), 'utf-8') | ||
} | ||
|
||
presentations_list.append(talk) | ||
|
||
except IOError: | ||
log.exception("CSV: File %s not found", csv_file) | ||
|
||
return presentations_list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Core] | ||
Name = Rss FeedParser | ||
Module = rss_feedparser | ||
|
||
[Documentation] | ||
Author = Rio Lowry | ||
Version = 3.0.9999 | ||
Website = http://fosslc.org | ||
Description = Rss FeedParser plugin provides a RSS parser used when adding presentations |
119 changes: 119 additions & 0 deletions
119
src/freeseer/plugins/importer/rss_feedparser/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# freeseer - vga/presentation capture software | ||
# | ||
# Copyright (C) 2013 Free and Open Source Software Learning Centre | ||
# http://fosslc.org | ||
# | ||
# 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/>. | ||
|
||
# For support, questions, suggestions or any other inquiries, visit: | ||
# http://wiki.github.com/Freeseer/freeseer/ | ||
|
||
""" | ||
Rss FeedParser | ||
-------------- | ||
An import plugin which provides a RSS parser used when adding presentations | ||
@author: Rio Lowry | ||
""" | ||
|
||
from HTMLParser import HTMLParser | ||
|
||
from feedparser import parse | ||
|
||
from freeseer.framework.plugin import IImporter | ||
|
||
|
||
class MLStripper(HTMLParser): | ||
"""Simple stripper to remove markup | ||
MLStripper from http://stackoverflow.com/a/925630/72321 | ||
""" | ||
def __init__(self): | ||
self.reset() | ||
self.fed = [] | ||
|
||
def handle_data(self, d): | ||
self.fed.append(d) | ||
|
||
def get_data(self): | ||
return ''.join(self.fed) | ||
|
||
|
||
def strip_tags(html): | ||
"""Helper functions to strip markup from passed object""" | ||
s = MLStripper() | ||
s.feed(html) | ||
return s.get_data() | ||
|
||
|
||
class FeedParser(IImporter): | ||
"""FeedParser plugin for Freeseer | ||
Provides functionality to allow a RSS feed to be fetched and parsed | ||
""" | ||
|
||
name = "Rss FeedParser" | ||
os = ["linux", "linux2"] | ||
|
||
def get_presentations_list(self, feed_url): | ||
"""Takes feed_url, fetches, parses feed_url | ||
Returns list of dictionaries of all presentations on parsed feed. | ||
""" | ||
parsed_feed = parse(feed_url) | ||
self.presentations = parsed_feed.entries | ||
self.presentations_length = len(self.presentations) | ||
self.presentation_list = [] | ||
for i, entry in enumerate(self.presentations): | ||
pres_data = entry["summary_detail"]["value"] | ||
|
||
# We want to split the pres_data by 3 spaces because some field | ||
# data contain spaces and we don't want to erroneously split that | ||
# data. | ||
|
||
pres_data = filter(None, pres_data.split(" ")) | ||
|
||
presentation = {'Title': entry.title.strip(), | ||
'Speaker': self.get_presentation_field(pres_data, "field-field-speaker"), | ||
'Abstract': self.get_presentation_field(pres_data, "field-field-abstract"), | ||
'Level': self.get_presentation_field(pres_data, "field-field-level"), | ||
'Status': self.get_presentation_field(pres_data, "field-field-status"), | ||
'Time': self.get_presentation_field(pres_data, "field-field-time"), | ||
'Event': self.get_presentation_field(pres_data, "field-field-event"), | ||
'Room': self.get_presentation_field(pres_data, "field-field-room") | ||
} | ||
self.presentation_list.append(presentation) | ||
|
||
return self.presentation_list | ||
|
||
def get_presentation_field(self, presentation, field_name): | ||
"""Returns the field_name of the presentation at presentation""" | ||
|
||
# Due to the autogenerated structure of the rss feed the field data is | ||
# offset by 4 elements from field_name in the passed presentation | ||
|
||
item_presentation_offset = 4 | ||
for i, element in enumerate(presentation): | ||
if field_name in element: | ||
|
||
# data in element is in unicode, we want an error raised if | ||
# there are characters that we are not expecting | ||
|
||
field_data = unicode(presentation[i + item_presentation_offset]) | ||
|
||
return strip_tags(field_data).strip() |
Oops, something went wrong.