Photo by Pixabay on Pexels.com

steamのAPIを使用して積みゲーを調べてみました.積みゲー有り

2024.08.27

Logging

おはようございます.xAIの申請に通らなかったので来月のQiitaの投稿を何にしようかなと考えてた所、ふと積みゲーのことが頭に浮かんできたので、Steam APIとかあるのかなと調べてみました.そしたらAPIが在ったのでさっそく作ってみました.

ソースコードはgithubにもあげているので試してみてください.こちらのソースコードをコピペするよりお手軽ですよ.

https://github.com/taoka3/steam/tree/main

<?php
require 'config.php';

class steam
{

    public $result;

    public function getOwnedGames($urls = 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v1/?')
    {
        $params = http_build_query([
            'key'=>APIKEY,
            'steamid'=>STEAMID,
            'include_appinfo'=>1,
            'include_played_free_games'=>0,
            //'appids_filter'=>''
        ]);
         $this->result = file_get_contents($urls.$params,true);
         return $this;
    }

    public function viewOwnedGames()
    {
        $data = json_decode($this->result);
        
        foreach($data->response->games as $val){
            $tumiGames = (int)$val->playtime_forever === 0?' [積みゲー]':'';
            printf('ゲーム名:%s プレイ時間:%02d時%02d分%s<br>',$val->name,(int)($val->playtime_forever / 60),(int)($val->playtime_forever % 60),$tumiGames);
        }
        return $this;
    }
}

(new steam)->getOwnedGames()->viewOwnedGames();

    

因みに実行結果は下記になります.

明日へ続く.

著者名  @taoka_toshiaki

※この記事は著者が40代前半に書いたものです.

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

$params, APIKEY, foreach, getOwnedGames, github, gt, int, json_decode, lt, php require, printf, public, qiita, response, result, return, STEAMID, URLs, val, xAI,

任意のディレクトリ連番を調べてURLを返却する.

2024.06.21

Logging

おはようございます、任意のディレクトリ連番を調べてURLを返却するPHP言語のコードです.このコードは昨日に書いた記事を読んで頂けたら分かると思いますが、ある配下のディレクトリ名が連番で名前付けしていたら、その連番のディレクトリを確認してindex.phpかindex.htmlが存在したらindexページを返却し無ければ、そのディレクトリ内にあるphpファイルのリンクアドレスを返却するようになっています.

<?php
class lists
{
    public $toolDir;
    public $toolUrl;

    public function __construct($toolDir = __DIR__ . '/../', $toolUrl = 'https://zip358.com/tool/')
    {
        $this->toolDir = $toolDir;
        $this->toolUrl = $toolUrl;
    }

    public function getList($dir = 'demo', $max = 999)
    {
        $response = [];

        for ($i = 0; $i <= $max; $i++) {
            $demoDir = $dir . ($i ?: '');
            if (file_exists($this->toolDir . $demoDir . '/index.php')) {
                $response[] = $this->toolUrl . $demoDir . '/';
            } elseif (file_exists($this->toolDir . $demoDir . '/index.html')) {
                $response[] = $this->toolUrl . $demoDir . '/';
            } else {
                $filelist = scandir($this->toolDir . $demoDir, 1);
                foreach ($filelist as $file) {
                    $fileInfo = pathinfo($file);
                    $basename = $fileInfo["basename"];
                    $filename = $fileInfo["filename"];
                    if ($basename != $filename && $fileInfo["extension"] == "php") {
                        $response[] = $this->toolUrl . $demoDir . '/' . $filename . '.php';
                    }
                }
            }
        }
        return $response;
    }
}
<?php
require 'lists.php';
$res = (new lists())->getList();

使用する場合はindex.php側を呼び出してご自身のディレクトリ構造とURLなどに合わしてご使用ください.尚、変数の$resには配列が返却されます.

明日へ続く.

著者名  @taoka_toshiaki

※この記事は著者が40代前半に書いたものです.

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

$basename, construct, DIR, else, elseif, file_exists, filename, foreach, getList, gt, lt, pathinfo, php require, public, res, response, return, toolUrl, 連番, 配下,

ダミー情報を生成する定番.

2024.03.29

Logging

ダミー情報を生成する定番を生成する定番のコードを記載します.
Composerを使用し’faker’をインストールします.

composer require fakerphp/faker

使用方法例のコードとしてcsv出力するコードを記載(下記).

<?php
require 'vendor/autoload.php';
use Faker\Factory;

class CsvGenerate{
    /**
     * ダミー情報を生成する
     * @param int $max
     * @return string
     */
    public function csvMake(int $max=0):string
    {
        $faker = Factory::create('ja_JP');
        $hasData = [];
        for($i=0;$i<$max;$i++){
            $datas = [];
            $datas[0] = $faker->name();
            $datas[1] = $faker->email();
            $datas[2] = $faker->phoneNumber();
            $datas[3] = $faker->address();
            $hasData[$i] = implode(',',$datas);
        }

        return implode(PHP_EOL,$hasData);
    }
}

print((new CsvGenerate)->csvMake(1000));
//file_put_contents('data.csv',(new CsvGenerate)->csvMake(1000));

実際使用する場合は、file_put_contents行のコメントを解除してください.
同階層にdata.csvファイルが作成されます.
尚、コマンドよりファイルを実行することを想定しています.

※参考にしたサイト
https://fakerphp.github.io/
https://qiita.com/kurosuke1117/items/c672405ac24b03af2a90

明日へ続く.

著者名  @taoka_toshiaki

※この記事は著者が40代前半に書いたものです.

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

$datas, $hasData, Address, Composer, create, csvMake, faker’, gt, implode, items, lt, name, phoneNumber, php require, print, qiita.com, string, vendor,

MastodonAPIに先週の日曜日に鞍替え。#脱TwitterAPI有料化

2023.02.10

Logging

おはようございます、TwitterAPIの有料化始まりましたね😖。

企業ではどういう対応を取るのでしょうか。個人で作っていたサービスはサービス閉鎖する人達が増えてきましたね。自分もBotで高知県の企業を応援するサービスを作っていたのだけど、2月5日にサービスを停止しました。

このブログは予約投稿なので、これが配信された時にはTwitterから具体的なAPIの値段などが発表されていると思います。その発表次第ですがBotを再稼働するという選択も残っているのですが、どうなるかは分からないです。

そんな中でPHP言語を使用しMastodonのAPIを使って「投稿だけ」する。コードを書きましたのでお裾分けです。

https://qiita.com/taoka-toshiaki/items/483340a28c03a1828400

php Mastodon.php 'テスト投稿です'
<?php
require "config.php";
class Mastodon{
    const method = "POST";
    const host = "mstdn.jp";
    const endpoint  = "/api/v1/statuses";
    public static function toot($postdata = null)
    {
        if(!is_null($postdata)){
            $data = http_build_query($postdata);
            exec('curl -X POST -d "'.$data.'" --header "Authorization: Bearer '.ACCESSTOKEN.'" -sS https://'.self::host . self::endpoint.'; echo $?',$output);
            var_dump($output);
        }
    }
}
//    「未収載」    -> 'unlisted'
//    「公開」      -> 'public'
//    「非公開」    -> 'private'
//    「ダイレクト」 -> 'direct'
if($argv[1]){
    $postdata = [
        "visibility"=>"public",
        "status"=>strip_tags($argv[1]),
    ];
    Mastodon::toot($postdata);
}
<?php
define('ACCESSTOKEN','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');

著者名  @taoka_toshiaki

※この記事は著者が40代前半に書いたものです.

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

ACCESSTOKEN, API, argv, Authorization, Bearer, BOT, echo, endpoint, exec, gt, header, lt, mastodon, null, php define, php require, quot, toot, Twitter, TwitterAPI,