python3でmatplotlibのインストールメモ
OSはUbuntu 18.04.5 LTS
コマンドは下記
%pip3 install matplotlib
Leave record about python coding
python3でmatplotlibのインストールメモ
OSはUbuntu 18.04.5 LTS
コマンドは下記
%pip3 install matplotlib
python3でopenCVのインストールメモ
OSはUbuntu 18.04.5 LTS
コマンドは下記
%sudo apt install python3-opencv
頂点座標を空のnumpy.ndarrayに追加する操作。
よくやるのでメモ。
—(sample code)—–
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import cv2 import numpy as np ## cat pol_int (x-y point list) ## -126 133 ## -126 131 ## -117 131 ## -117 134 in_data = open("./plist") lines = in_data.readlines() arr = np.empty((0,2), int) for i in range(len(lines)): lines[i].strip() jj = lines[i].split() xx = int(jj[0]) yy = int(jj[1]) arr = np.append(arr, np.array([[xx, yy]]), axis=0) i = i + 1 print(arr) |
—(exec result)—–
[[-126 133]
[-126 131]
[-117 131]
[-117 134]]
—(memo)—-
initialize ndarray for x-y point list.
at first array is empty(no entry) and add_type is [x,y].
so initialize parameter is (0,2).
1 |
arr = np.empty((0,2), int) |
if append for ndarray, append element must ndarray.
we use only 1 axis, so axis = 0(axis memo)
1 |
arr = np.append(arr, np.array([[xx, yy]]), axis=0) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
var page = new WebPage(), testindex = 0, loadInProgress = false; page.onConsoleMessage = function(msg) { console.log(msg); }; page.onLoadStarted = function() { loadInProgress = true; }; page.onLoadFinished = function() { loadInProgress = false; }; var steps = [ function() { page.open("http://hogehoge_wordpress.com/wp-login.php"); }, function() { page.evaluate(function(){ document.getElementById("user_login").value="<user id>"; document.getElementById("user_pass").value="<user pass>"; document.querySelector('*[name="wp-submit"]').click(); }); }, function() { page.open('http://hogehoge_wordpress.com/wp-admin/post-new.php'); }, function() { page.evaluate(function() { document.querySelector('*[name="post_title"]').value='title'; document.querySelector('*[name="content"]').value='contents'; document.querySelector("#publish").click; var a = document.querySelectorAll("#publish"); var e = document.createEvent('MouseEvents'); e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); a[0].dispatchEvent(e); waitforload = true; }); }, function() { page.render('images/LastLoad.png'); } ]; interval = setInterval(function() { if (!loadInProgress && typeof steps[testindex] == "function") { console.log("step " + (testindex + 1)); steps[testindex](); page.render("images/step" + (testindex + 1) + ".png"); testindex++; } if (typeof steps[testindex] != "function") { page.render('images/finalxx.png'); console.log("Scrapping complete...!"); phantom.exit(); } }, 5000);// JavaScript Document |
Script sample to posting to wordpress by phantomjs.
まずはmechanizeのインストール
1 |
pip install mechanize |
ヤフーページにアクセスしてHTMLのソースを取得
1 2 3 4 5 6 |
#! /usr/bin/python import mechanize web = mechanize.Browser() hh = web.open( "http://yahoo.co.jp" ) print hh.read() |
wordpressに対して自動で記事を投稿するスクリプト。perlからMechanizeを使いWEBアクセスをエミュレートして書き込むやり方。何度か実行する機会があったのでここにメモ。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#! /usr/bin/perl use FindBin qw($Bin); use WWW::Mechanize; use utf8; $URI = 'http://your_wordpress_url/wp-admin/'; $agent = 'WWW::Mechanize'->new(); $agent->get("$URI"); $agent->submit_form( form_name => 'loginform', fields => { log => 'YOUR ID', pwd => 'YOUR PASSWORD', }, ); eval { $URI = $URI."post-new.php"; $agent->get("$URI"); $data = $agent->content; $agent->submit_form( form_name => 'post', fields => { 'post_title' => 'post title', 'content' => 'post contents', }, button => 'publish' ); }; if ($@) { print "err\n"; exit 1; }; exit 0; |
Script sample to posting to wordpress by perl and mechanize.