Merge branch 'master' of github.com:KevinMidboe/homehub

This commit is contained in:
2016-09-21 12:28:34 +00:00
98 changed files with 427 additions and 0 deletions

1
README.md Normal file
View File

@@ -0,0 +1 @@
# homehub

BIN
html/fonts/Roboto-Thin.ttf Executable file

Binary file not shown.

BIN
html/fonts/pixelHype.ttf Executable file

Binary file not shown.

BIN
html/images/cal/August.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 KiB

BIN
html/images/cal/Elias.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 KiB

BIN
html/images/cal/Kevin.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
html/images/day/Cloudy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
html/images/day/Fair.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
html/images/day/Fog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

BIN
html/images/day/Rain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
html/images/day/Sleet.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
html/images/day/Snow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

BIN
html/images/night/Fair.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

BIN
html/images/night/Fog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 886 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
html/images/night/Rain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
html/images/night/Sleet.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
html/images/night/Snow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

95
html/index.php Normal file
View File

@@ -0,0 +1,95 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name=viewport content="width=device-width, initial-scale=1">
<meta http-equiv="refresh" content="300">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<title>RPi Home Hub v0.1</title>
</head>
<body>
<div class="col-md-2 col-sm-2 text-center">
<div id="currTime"></div>
<div id="showerthoughts">
<h3>/r/showerthoughts</h3>
<p>
<?php echo file_get_contents("topSubPost.txt"); ?>
</p>
</div>
</div>
<div class="col-md-4 col-sm-4" id="timetables">
<h4 id="calTitle"></h4>
<img src="images/cal/Kevin.png" width="700px">
<img src="images/cal/Elias.png" width="700px">
<img src="images/cal/August.png" width="700px">
<img src="images/cal/Nora.png" width="700px">
</div>
<div class="col-md-3 col-sm-3 text-center weatherReport" style="margin-top: -40px;">
<div>
<e id="weatherImg"></e>
</div>
<p id="weatherTempValue"></p>
<p id="weatherRainfall"></p>
<p id="weatherWind"></p>
<p id="weatherWindDirection"></p>
</div>
<div class="clearfix"></div>
<div class="col-md-2 col-sm-2">
<h4 id="twitterTitle">@Politiet</h4>
<div class="twitterFeed">
<a class="twitter-timeline"
data-widget-id="685044306260918273"
href="https://twitter.com/TwitterDev"
data-chrome="nofooter noborders noheader transparent"
height="300">
Tweets by @Pooooolis
</a>
</div>
</div>
<div class="col-md-3 col-sm-3">
<h3 id="rssTitle">Siste fra ap.no</h3>
<span id="rssFeed">
<?php include 'phpFiles/apRss.php' ?>
</span>
</div>
<div class="col-md-3 col-sm-3">
<h3 id="rssTitle">Siste fra db.no</h3>
<span id="rssFeed">
<?php include 'phpFiles/dbRss.php' ?>
</span>
</div>
<script>window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));</script>
<script src="scripts/timeDateDisplay.js"></script>
<script src="scripts/cycleTimeplaner.js"></script>
<script src="scripts/3minReload.js"></script>
<script src="scripts/addWeatherInfo.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>

21
html/phpFiles/apRss.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
$rss = new DOMDocument();
$rss->load('http://www.aftenposten.no/eksport/rss-1_0/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 4;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<p>'.$description.'</p>';
}
?>

21
html/phpFiles/dbRss.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
$rss = new DOMDocument();
$rss->load('http://www.dagbladet.no/rss/nyheter/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
);
array_push($feed, $item);
}
$limit = 4;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
echo '<p>'.$description.'</p>';
}
?>

View File

@@ -0,0 +1,3 @@
setInterval(function() {
window.location.reload();
}, 300000);

View File

@@ -0,0 +1,15 @@
var weatherData = [];
$.get('weatherData.txt', function(data) {
weatherData = data.split("\n");
var elem = document.createElement("img");
elem.setAttribute("src", 'images/' + weatherData[0] + '/' + weatherData[1]);
elem.setAttribute("height", "180");
elem.setAttribute("width", "180");
elem.setAttribute("alt", weatherData[1]);
document.getElementById("weatherImg").appendChild(elem);
document.getElementById("weatherTempValue").innerHTML = "<p class='weatherTitle' style='font-size: 30px;'>Temperatur</p><p class='weatherData' style='font-size: 35px;'>" + weatherData[2] + '°</p>';
document.getElementById("weatherRainfall").innerHTML = "<p class='weatherTitle'>Nedbør</p><p class='weatherData'>" + weatherData[3] + '</p>';
document.getElementById("weatherWind").innerHTML = "<p class='weatherTitle'>Vind</p><p class='weatherData'>" + weatherData[5] + '</p>';
document.getElementById("weatherWindDirection").innerHTML = "<p class='weatherTitle'>Vind rettning</p><p class='weatherData'>" + weatherData[6] + '</p>';
});

View File

@@ -0,0 +1,28 @@
var imageIndex = 0;
changeBanner();
function changeBanner(){
var img = [];
var timetableImages = document.getElementById('timetables');
img[0] = timetableImages.getElementsByTagName('img')[0];
img[1] = timetableImages.getElementsByTagName('img')[1];
img[2] = timetableImages.getElementsByTagName('img')[2];
for (var i = 0; i < img.length; i++) {
img[i].style.display = 'none';
}
img[imageIndex].style.display = 'block';
var src = img[imageIndex].src;
if(src.indexOf('/') >= 0) {
src = src.substring(src.lastIndexOf('/')+1);
src = src.replace('.png', ' sin timeplan');
document.getElementById('calTitle').innerHTML = src;
}
if (imageIndex == img.length - 1) {
imageIndex = 0;
} else { imageIndex++; }
}
setInterval('changeBanner()', 5000);

View File

@@ -0,0 +1,31 @@
var weekday = new Array(7);
weekday[0]= "Søndag";
weekday[1] = "Mandag";
weekday[2] = "Tirsdag";
weekday[3] = "Onsdag";
weekday[4] = "Torsdag";
weekday[5] = "Fredag";
weekday[6] = "Lørdag";
(function () {
function checkTime(i) {
return (i < 10) ? "0" + i : i;
}
function startTime() {
var today = new Date(),
h = checkTime(today.getHours()),
m = checkTime(today.getMinutes()),
s = checkTime(today.getSeconds());
dn = weekday[today.getDay()];
d = checkTime(today.getDate());
mon = checkTime(today.getMonth() + 1);
y = checkTime(today.getFullYear());
document.getElementById('currTime').innerHTML =
"<p id='time'>" + h + ":" + m + ":" + s + "</p><p>" + dn + " " + d + "." + mon + "." + y + "</p>";
t = setTimeout(function () {
startTime()
}, 500);
}
startTime();
})();

121
html/style.css Normal file
View File

@@ -0,0 +1,121 @@
@font-face { font-family: pixelHype; src: url('fonts/Roboto-Thin.ttf');}
html, body {
font-family: pixelHype;
font-size: 24px;
padding: 20px;
}
#time {
border: solid;
border-width: 1.5px;
border-color: black;
border-radius: 8px;
background-color: black;
color: white;
padding: 3px;
font-size: 58px;
}
#showerthoughts h3 {
border: solid;
border-width: 1.5px;
border-color: black;
border-radius: 8px;
background-color: black;
color: white;
clear:both;
float:left;
padding: 3px;
}
#showerthoughts p {
text-align: left;
clear: both;
float: left;
}
.weatherReport {
margin-right: -30px;
margin-left: -30px;
}
.weatherTitle {
width: 50%;
float: left;
text-align: right;
padding-right: 15px;
}
.weatherData {
width: 50%;
float:right;
text-align: left;
padding-left: 15px;
}
#rssTitle {
border: solid;
border-width: 1.5px;
border-color: black;
border-radius: 8px;
background-color: black;
color: white;
width: 165px;
padding: 3px;
}
#rssFeed {
font-size: 15px;
}
#twitterTitle {
border: solid;
border-width: 1.5px;
border-color: black;
border-radius: 8px;
background-color: black;
color: white;
clear:both;
float:left;
padding: 3px;
margin-left: 8px;
}
.twitterFeed {
border: solid;
border-width: 1px;
border-color: black;
border-radius: 8px;
padding-left: 8px;
}
#calTitle {
border: solid;
border-width: 1.5px;
border-color: black;
border-radius: 8px;
background-color: black;
color: white;
clear:both;
float:left;
padding: 3px;
}
#timetables {
width: 735px;
padding-bottom: 20px;
margin-left: 20px;
margin-right: 45px;
margin-bottom: 20px;
border: solid;
border-width: 1px;
border-color: black;
border-radius: 8px;
}
#timetables img {
display: none;
}

83
html/topRedditPost.py Normal file
View File

@@ -0,0 +1,83 @@
import praw
import ephem
import requests
user_agent = ("topRedditPost pyMachine 0.1")
submissionArray = []
weatherURL = 'http://www.yr.no/place/Norway/Oslo/Oslo/Ljabru/hour_by_hour.html'
weatherURL1 = 'http://www.yr.no/place/Norway/Sør-Trøndelag/Trondheim/Utleirvegen/hour_by_hour.html'
stringId = '<meta property="og:description" content="'
def getShowerThought():
r = praw.Reddit(user_agent = user_agent)
subreddit = r.get_subreddit("showerthoughts")
for submission in subreddit.get_hot(limit = 5):
submissionArray.append(submission.title)
with open('topSubPost.txt', 'w') as outputFile:
print(submissionArray[2])
outputFile.write(str(submissionArray[2]))
def timeOfDay():
user = ephem.Observer()
user.lat = '63.394079063'
user.lon = '10.424076010'
user.elevation = 118
next_sunrise_datetime = user.next_rising(ephem.Sun()).datetime()
next_sunset_datetime = user.next_setting(ephem.Sun()).datetime()
if (next_sunset_datetime < next_sunrise_datetime):
return "day"
else:
return "night"
def getWeatherReport():
page = str(requests.get(weatherURL).content)
idIndex = page.index(stringId) + len(stringId)
forcastDescription = page[idIndex:idIndex + page[idIndex:].index('/>') - 2]
forcastList = forcastDescription.split(', ')
# Get the worded weather state
weatherState = forcastList[0]
while True:
try:
weatherState.index(':')
weatherState = weatherState[weatherState.index(':') + 2:]
pass
except ValueError:
forcastList[0] = weatherState + '.png'
break
# Get the temp value
tempValue = forcastList[1]
forcastList[1] = tempValue[12:]
# Clean up any errors in the downpour
try:
forcastList[2] = forcastList[2].replace("\\xe2\\x80\\x93", "-")
except ValueError:
pass
# Get the wind value and append the direction of the wind
windValue = windDir = forcastList[4]
windValue = windValue[:windValue.index('from') - 1]
windDir = windDir[windDir.index('from') + len('from') + 1:]
forcastList[4] = windValue
forcastList.append(windDir)
# Get the time of day
forcastList.insert(0,timeOfDay())
print(forcastList)
with open('weatherData.txt', 'w') as outputFile:
for element in forcastList:
outputFile.write(str(element) + '\n')
def main():
getShowerThought()
getWeatherReport()
main()

1
html/topSubPost.txt Normal file
View File

@@ -0,0 +1 @@
"No Man's Land" is a great name for a lesbian bar

7
html/weatherData.txt Normal file
View File

@@ -0,0 +1,7 @@
day
Snow.png
-6
0.4 - 0.7 mm
Gentle breeze
6 m/s
northeast