Merged older paper pi with the newer, with some recent updates.
This commit is contained in:
42
app/Http/Controllers/ClosedShops.php
Normal file
42
app/Http/Controllers/ClosedShops.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Paper\Paper;
|
||||
|
||||
class ClosedShops extends Controller
|
||||
{
|
||||
|
||||
private $icon = 'frown-o';
|
||||
private $daysClosed = ['11-03','18-03',
|
||||
'01-04','02-04','08-04','15-04','22-04',
|
||||
'01-05','03-05','13-05','20-05','31-05',
|
||||
'10-06','17-06',
|
||||
'08-07','15-07','22-07',
|
||||
'12-08','15-08','19-08',
|
||||
'09-09','16-09','23-09',
|
||||
'14-10','21-10',
|
||||
'01-11','11-11','18-11',
|
||||
'09-12','16-12','25-12','16-12'
|
||||
];
|
||||
|
||||
private $paper;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->paper = new Paper();
|
||||
}
|
||||
|
||||
|
||||
public function tomorrow()
|
||||
{
|
||||
$today = new \DateTime();
|
||||
$tomorrow = $today->modify('+1 day');
|
||||
if(in_array($tomorrow->format('d-m'), $this->daysClosed)){
|
||||
$this->paper->sendPrint('Jutro sklepy są zamknięte.', "Jutrzejszy dzień jest dniem \nwolnym od handlu ponieważ jutro \njest święto albo niedziela wolna \nod handlu\n\n".$tomorrow->format('d-m-Y'), $this->icon);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
26
app/Http/Controllers/Keyboard.php
Normal file
26
app/Http/Controllers/Keyboard.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Paper\CinemaMultikino;
|
||||
use DiDom\Query;
|
||||
use Illuminate\Http\Request;
|
||||
use DiDom\Document;
|
||||
use App\Paper\Paper;
|
||||
|
||||
class Keyboard extends Controller
|
||||
{
|
||||
|
||||
private $paper;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->paper = new Paper();
|
||||
}
|
||||
|
||||
public function press($key)
|
||||
{
|
||||
$this->paper->sendPrint($key);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,10 @@
|
||||
*/
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
set_time_limit(-1);
|
||||
|
||||
use App\Paper\HtmlToPos;
|
||||
use App\Paper\Airly;
|
||||
use App\Paper\Paper;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
|
||||
use Mike42\Escpos\Printer;
|
||||
@@ -19,6 +21,20 @@ use Illuminate\Http\Request;
|
||||
class Main extends Controller
|
||||
{
|
||||
|
||||
private $paper = null;
|
||||
const TEMPLATE = 'template';
|
||||
const NOTE = 'note';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->paper = new Paper();
|
||||
}
|
||||
|
||||
/**
|
||||
* post::/printImage
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function imagePrint(Request $request)
|
||||
{
|
||||
|
||||
@@ -103,89 +119,130 @@ class Main extends Controller
|
||||
return back();
|
||||
}
|
||||
|
||||
/**
|
||||
* get:/
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function listView(Request $request)
|
||||
{
|
||||
$notes = DB::select('SELECT * FROM note ORDER BY updated_at DESC');
|
||||
$notes = DB::select('SELECT * FROM note WHERE type = "note" ORDER BY updated_at DESC');
|
||||
$templates = DB::select('SELECT * FROM note WHERE type = "template" ORDER BY updated_at DESC');
|
||||
return view('list', [
|
||||
'notes' => $notes,
|
||||
'templates' => $templates,
|
||||
'title' => $request->old('title'),
|
||||
'text' => $request->old('text')
|
||||
'text' => $request->old('text'),
|
||||
'icon_selected' => $request->old('icon'),
|
||||
'icons' => $this->paper->getIcons()
|
||||
]);
|
||||
}
|
||||
|
||||
public function form(Request $request)
|
||||
/**
|
||||
* get:/airly
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function airly(Request $request)
|
||||
{
|
||||
return view('create', [
|
||||
'title' => $request->old('title'),
|
||||
'text' => $request->old('text')
|
||||
]);
|
||||
$airly = new Airly();
|
||||
$this->paper->sendImagePrint('cloud.png');
|
||||
$this->paper->sendHeaderPrint('Jakość powietrza:' . PHP_EOL . date('H:i d-m-Y'));
|
||||
foreach ($airly->getStations() as $stationId) {
|
||||
$stationInfo = $airly->getStationInfo($stationId);
|
||||
$this->paper->sendHeaderPrint($stationInfo['address']['locality'] . ' ' . $stationInfo['address']['route']);
|
||||
$dataText = $airly->getInformationText($stationId);
|
||||
$this->paper->sendPrint('', $dataText);
|
||||
}
|
||||
return back();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* post::/print/{id}
|
||||
* @param $id
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function printText($id)
|
||||
{
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
$this->sendPrint($note->topic, $note->text);
|
||||
$this->paper->sendPrint($note->topic, $note->text, $note->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
private function templateReplace($input){
|
||||
|
||||
return str_replace(['[d]', '[m]', '[y]', '[h]', '[i]', '[s]'],
|
||||
[date('d'), date('m'), date('Y'), date('H'), date('i'), date('s')],
|
||||
$input);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* get::/edit/{id}/{slug}
|
||||
* post::/edit/{id}/{slug}
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
* @param $slug
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function edit(Request $request, $id, $slug)
|
||||
{
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
if ($request->isMethod('post')) {
|
||||
if ($request->exists('save')) {
|
||||
DB::table('note')
|
||||
->where('id', $note->id)
|
||||
->update([
|
||||
'topic' => $request->input('title'),
|
||||
'topic_slug' => str_slug($request->input('title'), '_'),
|
||||
'text' => $request->input('text'),
|
||||
'updated_at' => time(),
|
||||
]);
|
||||
if ($request->exists('save') ||
|
||||
$request->exists('save_template')) {
|
||||
if ($note->type == $this::TEMPLATE) {
|
||||
$id = DB::table('note')
|
||||
->insertGetId([
|
||||
'topic' => $this->templateReplace($request->input('title')),
|
||||
'topic_slug' => str_slug($request->input('title'), '_'),
|
||||
'text' => $this->templateReplace($request->input('text')),
|
||||
'icon' => $request->input('icon'),
|
||||
'type' => self::NOTE,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time()
|
||||
]);
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
} else {
|
||||
DB::table('note')
|
||||
->where('id', $note->id)
|
||||
->update([
|
||||
'topic' => $request->input('title'),
|
||||
'topic_slug' => str_slug($request->input('title'), '_'),
|
||||
'text' => $request->input('text'),
|
||||
'icon' => $request->input('icon'),
|
||||
'updated_at' => time(),
|
||||
]);
|
||||
}
|
||||
} elseif ($request->exists('delete')) {
|
||||
DB::table('note')
|
||||
->where('id', $note->id)
|
||||
->delete();
|
||||
|
||||
return redirect()->route('list');
|
||||
|
||||
} elseif ($request->exists('print')) {
|
||||
$this->sendPrint($request->input('title'), $request->input('text'));
|
||||
$this->paper->sendPrint($request->input('title'), $request->input('text'), $request->input('icon'));
|
||||
}
|
||||
return redirect()->route('edit', ['id' => $note->id, 'slug' => $note->topic_slug]);
|
||||
} else {
|
||||
return view('edit', [
|
||||
'title' => $note->topic,
|
||||
'text' => $note->text,
|
||||
'icon_selected' => $note->icon,
|
||||
'type' => $note->type,
|
||||
'id' => $note->id,
|
||||
'icons' => $this->paper->getIcons(),
|
||||
'topic_slug' => $note->topic_slug,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function sendPrint($title, $text)
|
||||
{
|
||||
$connector = new FilePrintConnector("/dev/usb/lp0");
|
||||
$printer = new Printer($connector);
|
||||
|
||||
|
||||
|
||||
// $printer->setFont(Printer::FONT_B);
|
||||
if (strlen($title)) {
|
||||
$printer->setDoubleStrike(true);
|
||||
$printer->setJustification(Printer::JUSTIFY_CENTER);
|
||||
$printer->setEmphasis(true);
|
||||
$printer->text($title . "\n\n");
|
||||
$printer->setEmphasis(false);
|
||||
$printer->setJustification(Printer::JUSTIFY_LEFT);
|
||||
$printer->setDoubleStrike(false);
|
||||
}
|
||||
$htmlToPos = new HtmlToPos();
|
||||
$printer->text($htmlToPos->convert($text));
|
||||
|
||||
$printer->feed(4);
|
||||
$printer->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* post::/
|
||||
* @param Request $request
|
||||
* @return $this|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function main(Request $request)
|
||||
{
|
||||
if ($request->exists('save')) {
|
||||
@@ -194,13 +251,28 @@ class Main extends Controller
|
||||
'topic' => $request->input('title'),
|
||||
'topic_slug' => str_slug($request->input('title'), '_'),
|
||||
'text' => $request->input('text'),
|
||||
'icon' => $request->input('icon'),
|
||||
'type' => self::NOTE,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time()
|
||||
]);
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
return redirect()->route('edit', ['id' => $note->id, 'slug' => $note->topic_slug]);
|
||||
} elseif ($request->exists('save_template')) {
|
||||
$id = DB::table('note')
|
||||
->insertGetId([
|
||||
'topic' => $request->input('title'),
|
||||
'topic_slug' => str_slug($request->input('title'), '_'),
|
||||
'text' => $request->input('text'),
|
||||
'icon' => $request->input('icon'),
|
||||
'type' => self::TEMPLATE,
|
||||
'created_at' => time(),
|
||||
'updated_at' => time()
|
||||
]);
|
||||
$note = DB::table('note')->where('id', $id)->first();
|
||||
return redirect()->route('edit', ['id' => $note->id, 'slug' => $note->topic_slug]);
|
||||
} else {
|
||||
$this->sendPrint($request->input('title'), $request->input('text'));
|
||||
$this->paper->sendPrint($request->input('title'), $request->input('text'), $request->input('icon'));
|
||||
return back()->withInput();
|
||||
}
|
||||
|
||||
|
||||
110
app/Http/Controllers/PacktPub.php
Normal file
110
app/Http/Controllers/PacktPub.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Paper\CinemaMultikino;
|
||||
use DiDom\Query;
|
||||
use Illuminate\Http\Request;
|
||||
use DiDom\Document;
|
||||
use App\Paper\Paper;
|
||||
|
||||
class PacktPub extends Controller
|
||||
{
|
||||
|
||||
private $main;
|
||||
private $icon = '/small/book.png';
|
||||
|
||||
private $freeBook = 'https://www.packtpub.com/packt/offers/free-learning';
|
||||
|
||||
|
||||
private $loginData;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->paper = new Paper();
|
||||
$this->loginData = array(
|
||||
'email' => 'krzysiej@gmail.com',
|
||||
'password' => 'korki1korki1',
|
||||
'op' => 'Login',
|
||||
'form_build_id' => '',
|
||||
'form_id' => 'packt_user_login_form',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function today()
|
||||
{
|
||||
|
||||
$data = file_get_contents($this->freeBook);
|
||||
$document = new Document($data);
|
||||
|
||||
// list(,,$id,)= explode('/', $document->first('//form[@id="free-learning-form"]/@action', Query::TYPE_XPATH));
|
||||
$id = $document->first('//input[@id="free-learning-register-claim-title-nid"]/@value', Query::TYPE_XPATH);
|
||||
|
||||
$myBooksRaw = $this->c('https://www.packtpub.com/account/my-ebooks', $this->loginData);
|
||||
|
||||
print_r($myBooksRaw);
|
||||
$myBooks = new Document($myBooksRaw);
|
||||
|
||||
// $x = $myBooks->first('//div[@nid="' . $id . '"]', Query::TYPE_XPATH);
|
||||
|
||||
var_dump($id);
|
||||
|
||||
var_dump('//div[@nid="' . $id . '"]');
|
||||
$isOwnd = (bool)$myBooks->first('//div[@nid="' . $id . '"]', Query::TYPE_XPATH);
|
||||
|
||||
var_dump($isOwnd);
|
||||
die();
|
||||
$titleNode = $document->first('.dotd-title h2');
|
||||
|
||||
if ($titleNode) {
|
||||
$title = trim($titleNode->text());
|
||||
}
|
||||
|
||||
$descriptionNodes = $document->find('//div[contains(@class,"dotd-main-book-summary")]/div[not(@class)]', Query::TYPE_XPATH);
|
||||
$descriptionText = '';
|
||||
if ($descriptionNodes) {
|
||||
foreach ($descriptionNodes as $node) {
|
||||
$descriptionText .= trim($node->text()) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
$descriptionText .= "\n\n" . (($isOwnd) ? 'Masz już tę książkę w biblioteczce.' : 'Nie masz jeszcze tej książki.');
|
||||
$descriptionText .= "\n\n" . date('Y-m-d');
|
||||
|
||||
|
||||
$imageNode = $document->first('//div[contains(@class, "dotd-main-book")]//img[contains(@class, "bookimage")]/@src', Query::TYPE_XPATH);
|
||||
if ($imageNode) {
|
||||
$imageNode = str_replace(' ', '%20', $imageNode);
|
||||
|
||||
$this->paper->sendPrint($title, $descriptionText, 'https:' . $imageNode, false);
|
||||
}
|
||||
}
|
||||
|
||||
private function c($url, $postArray = null)
|
||||
{
|
||||
$cookie = __DIR__ . '/cookie.txt';
|
||||
$ch = curl_init();
|
||||
$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6";
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||||
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
|
||||
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
|
||||
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
if (!is_null($postArray)) {
|
||||
curl_setopt($ch, CURLOPT_POST, TRUE);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postArray));
|
||||
}
|
||||
$result = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -2,18 +2,19 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Paper\CinemaMultikino;
|
||||
use DiDom\Document;
|
||||
use App\Paper;
|
||||
use App\Paper\Paper;
|
||||
|
||||
class Repertoire extends Controller
|
||||
{
|
||||
|
||||
private $main;
|
||||
private $icon = '/small/film.png';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->main = new Main();
|
||||
$this->main = new Paper();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +22,7 @@ class Repertoire extends Controller
|
||||
{
|
||||
$date = date('d/m/Y');
|
||||
$repertuarText = $this->cinemacityRepertuar($date);
|
||||
$this->main->sendPrint('', $repertuarText);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
@@ -31,7 +32,7 @@ class Repertoire extends Controller
|
||||
$date = new \DateTime();
|
||||
$date->modify('+1 day');
|
||||
$repertuarText = $this->cinemacityRepertuar($date->format('d/m/Y'));
|
||||
$this->main->sendPrint('', $repertuarText);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
@@ -81,9 +82,10 @@ class Repertoire extends Controller
|
||||
|
||||
public function today_multikino()
|
||||
{
|
||||
$multikino = new Paper\CinemaMultikino();
|
||||
$multikino = new CinemaMultikino();
|
||||
|
||||
$repertuarText = $multikino->convertToPrint(date('Y-m-d'), 4);
|
||||
$this->main->sendPrint('', $repertuarText);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
@@ -92,13 +94,12 @@ class Repertoire extends Controller
|
||||
$date = new \DateTime();
|
||||
$date->modify('+1 day');
|
||||
|
||||
$multikino = new Paper\CinemaMultikino();
|
||||
$multikino = new CinemaMultikino();
|
||||
$repertuarText = $multikino->convertToPrint($date->format('Y-m-d'), 4);
|
||||
$this->main->sendPrint('', $repertuarText);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||
return back();
|
||||
|
||||
|
||||
|
||||
// $repertuarText = $this->multikinoRepertuar($date->format('Y-m-d'));
|
||||
// $this->main->sendPrint('', $repertuarText);
|
||||
// return back();
|
||||
@@ -111,7 +112,7 @@ class Repertoire extends Controller
|
||||
$date->modify('+1 day');
|
||||
|
||||
$repertuarText = $this->gdynskieCentrumFilmowe($date->format('d_m_Y'));
|
||||
$this->main->sendPrint('', $repertuarText);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
@@ -119,20 +120,20 @@ class Repertoire extends Controller
|
||||
{
|
||||
$date = date('d_m_Y');
|
||||
$repertuarText = $this->gdynskieCentrumFilmowe($date);
|
||||
$this->main->sendPrint('', $repertuarText);
|
||||
$this->main->sendPrint('', $repertuarText, $this->icon);
|
||||
return back();
|
||||
}
|
||||
|
||||
public function today_helios()
|
||||
{
|
||||
$this->main->sendPrint('', $this->helios(0, 2));
|
||||
$this->main->sendPrint('', $this->helios(0, 2), $this->icon);
|
||||
$this->main->sendPrint('', $this->helios(0, 49));
|
||||
return back();
|
||||
}
|
||||
|
||||
public function tomorrow_helios()
|
||||
{
|
||||
$this->main->sendPrint('', $this->helios(1, 2));
|
||||
$this->main->sendPrint('', $this->helios(1, 2), $this->icon);
|
||||
$this->main->sendPrint('', $this->helios(1, 49));
|
||||
return back();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user