#久しぶりのコード`Xにポストするコード`

20231117

Logging

おはよう御座います、さて正月休みは11日ぐらいあります、いやー正月休みはネトフリとゲームざんまいしてみたいと思っているのですが、結局どこかに出ていったりとかして目標達成できずにズルズルと休みを過ごすことになりそうです。👈前と言っていることが違いますね🙇。

さて、久しぶりにコードを書きました、この記事だけ見るとプログラマーじゃないかって思われるので最初に記載しときます。毎日のように仕事ではコードを書いています、仕事以外でコードを書いたのは一週間ぶりかなぁ。でも、このコードはポストでも書いている通り、特に難しいコードでもないのでオープンに公開しました。

このコードには必要ないコードが紛れているのはこのコードが使いましたコードだからです😂。

<?php
date_default_timezone_set('Asia/Tokyo');
ini_set("display_errors", 0);
require_once "../tw-config-v2.php";
require_once "../vendor/autoload.php";

use Abraham\TwitterOAuth\TwitterOAuth;

class merukari{
    public $connection = null;
    public $pdo = null;

    public function __construct()
    {
        $this->connection = new TwitterOAuth(APIKEY, APISECRET,ACCESSTOKEN,ACCESSTOKENSECRET);
        $this->connection->setApiVersion("2");
    }

    public function tweet($pattern)
    {
        $result = $this->connection->post("tweets", ["text" =>$pattern], true);
    }
    
    public static function pattern()
    {
        $pattern = [
            'メルカリで参考書を取り扱ってます📖 どれも綺麗な状態です。#学び #python Cシャープ #プログラム ⏭ https://jp.mercari.com/user/profile/808093563',
            'メルカリで参考書を出品してます📖 どれも綺麗な状態です。#学び #機械学習 #AI #プログラム ⏭ https://jp.mercari.com/user/profile/808093563',
            'メルカリで参考書を売ってます📖 どれも綺麗な状態です。#学び #人工知能 #python #プログラム ⏭ https://jp.mercari.com/user/profile/808093563',
            'メルカリで参考書を取り扱ってますよ📖 どれも綺麗な状態です。#学び #テック #企業 #学び #プログラム ⏭ https://jp.mercari.com/user/profile/808093563',
        ];

        return $pattern[ (int)rand(0,(count($pattern)-1))];
    }
}

try {
    if($argv[1] === 'merukari'){
        (new merukari())->tweet(merukari::pattern());
    }
} catch (\Throwable $th) {
    //throw $th;
}

もしかしたら、以前にもコードを公開して2回目になっていたりするかも知れません。そうだったらごめんなさい、無駄に記事を量産しています(反省。

そうそうXのハッシュタグ廃止は誤解だそうです。思い出したので書いときます、、、。

明日へ続く。

タグ

argv, Asia, catch, connection, construct, int, lt, null, pattern, Python, quot, rand, return, throw, Throwable, true, try, Tweet, use AbrahamTwitterOAuthTwitterOAuth, vendor,