常時ディレクトリ監視を行う方法。 #CPU使用率 #炎上

2022.11.03

Logging

おはようございます。何だかアカウントを作ってまでコメントする人の考えがわからない🤔。

Qiitaに、このコードのsleep関数がないバージョンをアップしたら、何やらアカウントを作ってまでコメントする人が現れる、理由はCPU使用率がMax近くになるのが駄目だからです、そんな事は分かっているのが普通だと思っていたのだけども…例文として掲載するのも駄目だそうです、コピペで運用する人が結構いるのかもしれない。

正直なところ、そこまで叩かれるとは思っていなかったので、正直なところ驚きを隠せない。段々と世間の常識とズレていっている気がします😗。

昔はそういうコードは巷に溢れていたのにな・・・そんな事も出来なくなってきたのか・・・。

トイウコトデ、常時ディレクトリ監視を行い任意の画像ファイルだけ別のディレクトリへ移動するコードです。

nohup php File_Check.php &
├── File_Check.php
├── upload
└── data
<?php
while(true){
    if($result = is_scandir("./upload")){
        foreach($result as $key=>$value){
            rename("./upload/$value","./data/$value");
        }
    }
    sleep(3);
}

function is_scandir(string $dirname="",array $ext_list = ["png","jpg"]){
    $is_filelest = [];
    $result = scandir($dirname);
    foreach($result as $key=>$value){
        $ext = substr($value, strrpos($value, '.') + 1);
        if(in_array($ext,$ext_list,false)!== false){
            $is_filelest[] = $value;
        }
    }
    return count($is_filelest)>0 ? $is_filelest : false;
}

タグ

check, CPU, file, max, nohup, php, qiita, sleep, アカウント, アップ, コード, コピペ, コメント, そこ, ディレクトリ, トイウコトデ, ところ, バージョン, ファイル, 世間, , , 任意, 使用, 例文, , , 常時, 常識, 掲載, 方法, , 普通, 正直, 段々, , 炎上, 理由, 画像, 監視, 移動, 近く, 運用, 関数, 駄目,

pythonで画像ダウンロードしたいなら。コレでよし🤔

2022.08.06

Logging

こんにちは、日が暮れて夕方になってしまいましたね?…本日の更新です😌。

今日は機械学習(tensorflow)の為の画像を集めをしていたました。画像を集めるのが面倒くさくて昔、ダウンロード用のソフトを自前で作っていたのだけど、その自前のソフトをいつの間にか消し去っていた為、再度Pythonで作り直しました。

作ったのですが、これは即席なダウンロードソフトなので完璧なものではないです。50枚~300枚の画像をダウンロード出来ます。そのダウンロードした画像を水回しして機械学習の画像分類に使用しているのですが、学習精度があまり良くないのが明日の課題。

人工知能に学習させる方法にはいろいろな方法があります。それらを上手く使えばもっと効率よく学習出来るみたいですが、そもそもPythonも普段から使用しないので手探り状態です。

もっと綺麗なコードを書けると思いますが…。

トイウコトデ、コードを記載しときますね、このコードはbingサイトで画像ダウンロードするために作られたものです。機械学習しているコードではありません。

from functools import cache
import time
import requests
import os
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
options = Options()
# download_path = 'C:\python\images\face'
# options.add_experimental_option("prefs", {"download.default_directory": download_path})
# driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.bing.com/images/search?q=顔&form=HDRSC2&first=1&tsc=ImageHoverTitle")
driver.set_window_size(945, 1012)
time.sleep(3)
sl = 700
for i in range(30):
    driver.execute_script("window.scrollTo(0," + str(sl) + ")")
    time.sleep(3)
    sl = sl + 700
img = []
for x in range(10):
    for y in range(100):
        try:
            txt = driver.find_element(By.XPATH,"//*[@id=\"mmComponent_images_2\"]/ul[" + str(int(y +1 )) +"]/li[" + str(int(x +1 )) +"]/div/div[1]/a").get_attribute("m")
            hoge = str(txt).split(",")
            #print(hoge)
            img.append([s for s in hoge if "murl" in s])
        except:
            print("errors not image")
driver.quit()
file_dir = "C:\\python\\images\\face\\"
for imgdata in img:
    url = str(imgdata).split(":")[1] + ":" + str(imgdata).split(":")[2]
    url = url.replace('"',"").replace("']","")
    print(url)
    try:
        urlData = requests.get(url).content
        with open(os.path.join(file_dir,os.path.basename(url)),'wb') as f:
            f.write(urlData)
    except:
        print("errors not Download")

タグ

ChromeDriverManager, driver, driver.get, driver.quit, except, img.append, imgdata, options, print, quot, replace, scrollTo, selenium.webdriver.support.wait, sl, sleep, tensorflow, time.sleep, ul, urlData, トイウコトデ,