Giter VIP home page Giter VIP logo

newsprint's Introduction

newsprint

The blog post and video that accompany this code give a general overview of the project.

Newsprint is a simple web application that will fetch the front page of a newspaper and display it on an eink display. The specific resolutions and sizes have been setup to work with a 32" eInk place & play display from Visionect but can be modified for other screen resolutions.

There are two portions to getting this up and running. The first is the application server that displays the newspaper. This code is setup to be run on a simple and low cost PHP webhost with very few dependancies. Simply copy the PHP files into a directory on your server and you should be good to go. You will need an "archive" folder on the server and the ability to call the command line "convert" utility to resize/convert images. Most hosts should have this installed as it's fairly standard.

The current newspapers that I've setup include the Boston Globe, New York Times, Wall St Journal, LA Times, Toronto Star and SF Chronical. Additional sources are easy to add by looking up the newspaper prefix on freedomforum.org. This is typically two letter State and newspaper abbreviation (NY_NYT or MA_BG). Each newspaper is then adjusted to display as much of the paper as possible. Many newspapers have a boarder or printing margin and I've tried to subtract this out in the samples.

The second portion of the software needed to get this running is the Visionect server. Information on the Visionect docker container and server are available for install. This has to run on the same network as the eInk display. The display itself is not standalone, it's a thin client and requires the Visionect software to act as an HTML rendering engine of sorts. The Visionect server software can be run on any docker server and general installation instructions are on the Visionect site. I was able to get it to run on my Synology server with a slightly modified file. The details of this are in the docker folder of this repo.

Affiliate link to Visionect eInk Display that was used

newsprint's People

Contributors

graiz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

newsprint's Issues

Front pages are a month behind

Recently my server began pulling front pages that were a month old. The index.php wasn't changed and I don't see any offsets that would be triggering this date pulling error. Any debugging suggestions?

`<?php
// Don't cache this page.
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

date_default_timezone_set('Etc/GMT-7'); // adjust for server timezone

// path to paper is base url +day of month + state + paper + .pdf
// https://cdn.freedomforum.org/dfp/pdf16/MA_BG.pdf

$news = array();
$paper['prefix']="DC_WP";$paper['style']="width:108%;margin:-5% -5% 0px -5%";array_push($news,$paper); // Washington Post
$paper['prefix']="NY_NYT";$paper['style']="width:99%;margin:-28px 14px 0px 3px";array_push($news,$paper); // New York Times
$paper['prefix']="CAN_TS";$paper['style']="width:90%;margin:-70px 0px 0px 0px";array_push($news,$paper);// Toronto Star
$paper['prefix']="IL_CT";$paper['style']="width:107%;margin:-5% -5% 0px -5%";array_push($news,$paper); // Chicago Tribune
$paper['prefix']="CA_LAT";$paper['style']="width:94%;margin:-2% 0px 0px 0px";array_push($news,$paper); // L.A. Times
$paper['prefix']="CA_SFC";$paper['style']="width:96%;margin:-20px 0px 0px 0px";array_push($news,$paper); // SF Chronical
$paper['prefix']="WA_ST";$paper['style']="width:100%;margin:-9% 0% 0px 0%";array_push($news,$paper); // Seattle Times
$maxPapers = count($news) -1;

// Loop a counter without a DB.
// allows us to get a different newspaper
// each load by asking for the counter
function getCounter() {
global $maxPapers;
$fp = fopen("counter.txt", "r");
if ($fp) {
$x= intval(fread($fp,1024));
fclose($fp);
} else {
$x = 0;
}
if ($x > $maxPapers) {
$x = 0;
}
if (!empty($_REQUEST['index'])) { // Override the counter if there
$x = $_REQUEST['index']; // is a URL parameter for index
}
return($x);
}
function incrementCounter(int $counter){
// increment the paper for next time
$counter++;
$fp = fopen("counter.txt", "w");
fwrite($fp, $counter);
fclose($fp);
}

// fetch a paper and cache in as a JPG. Return the path to the JPG if we found it.
// We can pass in an offset in days to get yesterday or two days ago
function fetchPaper($prefix, $offset=0){
$pathToPdf = "https://cdn.freedomforum.org/dfp/pdf" . date('j',strtotime("-" . $offset . " days")) . "/" . $prefix . ".pdf";
$pdffile = "archive/" . $prefix . "" . date('Ymd',strtotime("-" . $offset . " days")) . ".pdf";
$pngfile = "archive/" . $prefix . "
" . date('Ymd',strtotime("-" . $offset . " days")) . ".png";
$rootpath = getcwd() . "/";
// check if a jpg has already been created
// if not we start checking for the PDF and converting
if (!file_exists($pngfile)){
$file_headers = @get_headers($pathToPdf);
if(!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = false;
}
else {
$ch = curl_init($pathToPdf);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$exists = true;
$result = file_put_contents($pdffile, $data);
}
if ($exists) {
$command = "/usr/local/bin/convert -density 300 -background white -alpha remove '" . $rootpath . $pdffile .
"' -colorspace Gray -resize 1600 '" . $rootpath . $pngfile . "'";
exec($command, $output, $response);
}
} else {
$exists = true;
}
if ($exists) {
return $pngfile;
} else {
return false;
}
}
$currentIndex = getCounter();
if (isset($_REQUEST['index'])) {
$currentIndex = $_REQUEST['index'];
}

$imageresult = fetchPaper($news[$currentIndex]['prefix'],0); // Fetch today
if (empty($imageresult)) {
$imageresult = fetchPaper($news[$currentIndex]['prefix'],1); // yesterday
}
if (empty($imageresult)) {
$imageresult = fetchPaper($news[$currentIndex]['prefix'],2); // twesterday
}
?>

<style> body { text-align:center; } .paper { background-color:white; } </style> "; } ?> `

Subscription needed?

On the Visionect website, there is a note stating that a subscription is needed to use the display. I was curious about this and reached out to their support. They informed me that a subscription is required even for self-hosting.

Has anyone experienced whether this is true, or is there a way to bypass this requirement?

Error: "Newspaper File Not Found"

When I run the script, I get the error:

~/newsprint $ php index.php:

<!DOCTYPE html>
<html>
<head>
<style>
  body   { text-align:center; }
  .paper {
	background-color:white;
 	width:98%;margin:5px 10px 0px 8px  }
</style>
</head>
<body>
Newspaper File Not Found.  Will keep looking. Checking again in another hour.</div>
</body>
</html>

The URLs, however, seem valid.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.