Пример #1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $type = $input->getArgument('type');
     if (!in_array($type, array('picture', 'sound'))) {
         throw new InvalidArgumentException($type . ' is invalid. Only sound or picture are supported');
     }
     $dir = $input->getArgument('folder');
     if (!file_exists($dir)) {
         $dir = getcwd() . DIRECTORY_SEPARATOR . $dir;
         if (!file_exists($dir)) {
             throw new InvalidArgumentException($dir . ' is not exist.');
         }
     }
     $done_folder = $dir . DIRECTORY_SEPARATOR . 'done';
     @mkdir($done_folder, 0777);
     $client = new Client(['cookies' => true, 'track_redirects' => true, 'headers' => ['User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1']]);
     $http = new GuzzleHttpRequest($client);
     $course = new MoverCourse();
     $page = new LoginPage($http);
     $page->doLogin();
     $finder = new Finder();
     $cell_id = NULL;
     if ('picture' == $type) {
         $finder->files()->name('/\\.(jpg|jpeg|png|gif|bmp|tif)$/')->sortByName()->in($dir)->exclude('done');
         $cell_id = 4;
     } elseif ('sound' == $type) {
         $finder->files()->name('/\\.(mp3)$/')->sortByName()->in($dir)->exclude('done');
         $cell_id = 3;
     }
     foreach ($finder as $file) {
         /** @var SplFileInfo  $file */
         $output->writeln($file->getRealPath());
         // extract the WORD from filename
         $word = str_replace('.' . $file->getExtension(), '', $file->getFilename());
         // find the word and extract its id
         $page = new WordSearchPage($http, $course, $word);
         $thing_id = $page->getThingId();
         if ($thing_id) {
             $csrf_token = $page->getCsrfToken();
             $referer = $page->getFullUrl();
             // upload pictures
             $page = new UploadPage($http);
             if ($page->upload($csrf_token, $thing_id, $cell_id, $file->getRealPath())) {
                 rename($file->getRealPath(), $done_folder . DIRECTORY_SEPARATOR . $file->getFilename());
             }
         }
     }
 }
Пример #2
0
<?php

require './vendor/autoload.php';
use GuzzleHttp\Client;
use Vantt\Memrise\GuzzleHttpRequest;
use Vantt\Memrise\Page\LoginPage;
use Vantt\Memrise\MoverCourse;
use Vantt\Memrise\Page\UploadPage;
use Vantt\Memrise\Page\WordSearchPage;
$client = new Client(['cookies' => true, 'track_redirects' => true, 'headers' => ['User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1']]);
$http = new GuzzleHttpRequest($client);
$course = new MoverCourse();
$page = new LoginPage($http);
$page->doLogin();
$page = new WordSearchPage($http, $course, 'mammal');
$thing_id = $page->getThingId();
$csrf_token = $page->getCsrfToken();
$referer = $page->getFullUrl();
$page = new UploadPage($http);
$page->upload($csrf_token, $thing_id, 4, '/var/www/public/vocabulary-crawler/pictures/clothes/bag.jpg', $referer);
echo $html;