LoginSignup
0
1

More than 1 year has passed since last update.

週一でPython勉強会やってみる⑪

Posted at

前回の続き

先週はやる気が起きずパラっと読んで終了。長続きさせるには休むことも必要だと思う!

フォントの設定

文字サイズや太文字などの設定もできる。

from openpyxl.styles import Font
cell.font = Font(
    size = 14,
    bold = True,
    italic = True,
    color = 'FFFFFF'
)

背景色の設定

塗り方と色を設定する

from openpyxl.styles import PatternFill
cell.font = PatternFill(
    fill_type = 'solid',
    fgColor = 'FF0000'
)

エクセルを触るだけがPythonではないのでWebサイトを触ってみることにする

Requestsモジュール

使い方例↓

import requests

url = 'https://api.aoikujira.com/time/get.php'
result = requests.get(url)

print(result.text) # 現在時刻が表示される
print(resut.status_code) # ステータスコードが確認できる

ステータスコードは
200のほかに301302400などがある。
404はNot Foundで知ってる人は多のでは?

画像のダウンロード

画像もダウンロードすることができる。後々にやるが、入力なんかもできる。

import requests

url = 'https://uta.pw/shodou/img/3/3.png'

response = requests.get(url)

with open('gyudon.png', 'wb') as fp:
    fp.write(response.content)

wbwの書き込み用という指定、bはバイナリモードという指定になる。
ちなみにfpって何でしょうか・・・

「教えてChatGPT先生!!」

"fp" は、Pythonでファイルを扱う際によく使われる with open 文で使用される変数名の一つです。"fp" は "file pointer" の略であり、ファイルを指し示すポインタを表します。

だそうです。fとしてる人もいるのでややこさある・・・

ちょっとはPythonで色々できるようになってきたかもしれない。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1