Firestoreについて

データモデル 大きく3つの要素を指定することになります。 データ フィールドと値のペアを複数持っている(オブジェクト) ドキュメント 1つのデータを持っている ドキュメントのIDを指定する必要がある コレクション 複数のドキュメントを持っている コレ…

Providerとは

Providerとは Flutter開発において、初心者→中級者にステップアップする上で、Providerを使うというのは避けては通れない。Google社は、BloC Patternを使うことが2018年ぐらいに推奨していましたが、その後、アプリの規模に対して学習コストが高かったり、こ…

Flutter基本構造(書き方)

今回はアプリの基本構造(書き方)について紹介します。 以下のコードを解説したいと思います。 import 'package:flutter/material.dart' void main() { runApp(MyApp());} //起動時にmain関数呼び出し //main関数からrunApp関数を呼び出すことで、MyAppが実行…

【ytmusic】基本操作

import requestsfrom ytmusicapi import YTMusicimport json ytmusic = YTMusic("headers_auth.json") #プレイリスト作成→曲検索→検索結果をプレイリストに登録playlistId = ytmusic.create_playlist('test', 'test description')search_results = ytmusic.s…

【ytmusic】プレイリスト作成→曲検索→検索結果をプレイリストに登録

import requestsfrom ytmusicapi import YTMusicimport json ytmusic = YTMusic("headers_auth.json") #プレイリスト作成→曲検索→検索結果をプレイリストに登録playlistId = ytmusic.create_playlist('test', 'test description')search_results = ytmusic.s…

current user Section 11, Lecture 52

ログインしてるのにログイン画面に飛べるのを処理する。 以下のコードを設定するだけ良い。 if current_user.is_authenticated:はもしすでにログイン済みの場合はフラッシュメッセージを表示する。 @at.route('/login', methods=['GET', 'POST']) def do_the…

logging users out Section 11, Lecture 51

layout.htmlに以下を追加で記述して、各ファンクションとリンクさせる。 <li><a href="{{ url_for('main.display_books') }}"> Home </a></li> <li><a href="{{ url_for('authentication.register_user') }}"> Register </a></li> <li> {% if current_user.is_authenticated %} <a href="{{ url_for('authentication.log_out_user') }}"> SignOut </a> {…</li>

display login status Section 11, Lecture 50

ログイン状態か表示する方法 app/catalog/templates/layout.htmlに以下を追記する。 <a href=""> {% if current_user.is_authenticated %} Logged-In as <b style="color: deeppink"> {{ current_user.user_name.title() }} </b> {% else %} Not Logged-In {% endif %} </a> 実際にやってみる ログイン状態…

よくわkラン letting users login Section 11, Lecture 49

ログイン機能を改善する。 models.pyに以下を追記する ユーザーが入力したpasswordを渡すことでdbにあるハッシュと一致するかをチェックする。 def check_password(self, password): return bcrypt.check_password_hash(self.user_password, password) もし…

Flask-loginの説明 login manager and usermixin classes Section 11, Lecture 48

Flask Loginに関して models.pyに以下を記述することで login managerのloaderが使える。 int(id)にする必要がある。 今回はこの4つについて学ぶ 1. LoginManager 2. @login_manager.user_loader 3. load_user()custom method 4. UserMixin() auth/forms.py…

重複確認 writing custom validations Section 11, Lecture 47

すでにデータが存在しているかを確認する方法 forms.pyで文字数や有効性を確認をしていた。 forms.pyに関数を作る→forms.pyのチェック機能に重複確認関数を追加する必要がある。 def email_exists(form, field): email = User.query.filter_by(user_email=fi…

ユーザー登録のコード作成2 capturing user credentials using forms part 2 Section 11, Lecture 46

login.htmlを作る。 falseの場合はregistration.htmlに飛ばしてあげる。その場合はformも渡す。 flashメッセージ get_flash_messageに全てのメッセージが登録されている。 layout.htmlにflashを追加することで全てのページでflashメッセージを容易に表示させ…

ユーザー登録のコード作成1 capturing user credentials using forms part 1 Section 11, Lecture 45

route.pyのまとめ 次の順で処理される。 1. localhost/registerにアクセスする。 2. return render_template('registration.html', form=form)でページを表示させる。 3. HTMLからPOSTでname,emai,passwordが飛んでくる。 4. if form.validate_on_submit():…

フォームの作り方 adding data validation to the registration process Section 11, Lecture 44

validatorsを使う事でルール通りしか受け付けないようにする。 まとめ この4つの順に作ればフォームはできる。 1.フォームを作る 2.routeで登録する 3.dbのテーブルを定義する 4.htmlを作成する

basic user registration form and CSRF Section 11, Lecture 41

デフォルトではgetリクエストになる。 none設定をする 1. localhost/registerにアクセスする 2. GETリクエストなのでreturnでページを表示する 3. 次にuserがフォームを入力してsubmitを推した場合はPOSTなので ifぶんのPOSTを発動する。 4. returnにデータ…

creating users in the database Section 11, Lecture 43

models.pyを作る ユーザー管理用のデータベースを作る。 インスタンスではなくクラスを作る。 functionとして@classmethodを作る。 selfではなく、クラスなのでclsを置く。また、パスワードはハッシュ化する。 python3なのでutf-8の設定もする。 【通常の場…

bcryptの使い方の説明 flask login and password hashing using bcrypt Section 11, Lecture 42

bcryptの使い方の説明 最初にやる事は同じ 実際にpasswordをハッシュ化ってどんな風にやっているのか? Bcryptの'generate_password_hash'に注目する!これでハッシュ化する。 $ pip install flask_login $ pip install flask_bcrypt >>> from flask_bcrypt …

a simple form Section 11, Lecture 40

Catalog Packageと同じ流れやる 1. init.py, blueprint 2. app/init.pyに登録する 3. form.pyを作成する 4. route.pyを作成する(functionなど定義する) 5. htmlを準備する Authフォルダーにinit.pyを作る BluePrint をimportする。 blueprintのインスタンス…

Scaling Applications 最低限で動かす

最低限でblueprintを使いこなす。 上から順に書きなぐる Flaskは主にこの3つで構成される。 appフォルダー configフォルダー run.py ├── app │ ├── __init__.py │ ├── __pycache__ │ │ └── __init__.cpython-36.pyc │ ├── auth │ │ ├── __init__.py │ │ └──…

【Scrapy】Selenium

find_element_by_xpath-Python ◆メソッド ・find_element_by_xpath(xpath)◆使用形態 ・driver.find_element_by_xpath("//div/div/td[1]")◆備考 ・引数に取得したい要素のxpathを指定することで要素を取得できる ・引数で指定する属性値やインナーテキストな…

【Scrapy】Selenium

今回の章 セクション13:Scrapy with Selenium 今回の目的 各書籍のURLを取得」→「順に詳細ページをスクレイピング」→「次のページへ移動」→「各書籍のURLを取得」→「詳細ページをスクレイピング」というようなイメージでクローラーを動かせば良い。 独自プロ…

【Scrapy】Book Store Clawler

今回の章 セクション12:Building Web Crawler with Scrapy 今回の目的 Book Storeクローラー作成 → Class名をCrawlSpiderにする事でRuleを使えるようにする。 CrawlSpider Ruleは以下の通り rules = (Rule(LinkExtractor(), callback='parse_page', follow=T…

【Scrapy】quotes.toscrape.comのスパイダーを作ろう3/3

大きな流れ フィールド(箱)を用意する→スクレイプ(抽出&送る)を用意する→整形する。 アーキテクト Scrapy:クローラーを実装・運用するために欲しい機能がいろいろ用意されているItems:抽出したいデータ構造のモデルSpider:対象サイトへのリクエスト…

【Scrapy】quotes.toscrape.comのスパイダーを作ろう2/3

今回の章セクション:Building More Advanced Spider with Scrapy 14. Scrapy Advanced Spider - Part 115. Scrapy Advanced Spider - Part 2 16. Scrapy Advanced Spider - Part 3 17. Scrapy Advanced Spider - Part 4 18. Scrapy Architecture 今回の目的 …

【Scrapy】quotes.toscrape.comのスパイダーを作ろう1/3

今回の章 セクション:Building More Advanced Spider with Scrapy 14. Scrapy Advanced Spider - Part 115. Scrapy Advanced Spider - Part 2 16. Scrapy Advanced Spider - Part 3 17. Scrapy Advanced Spider - Part 4 18. Scrapy Architecture 今回の目的…

【Scrapy】Xpathの使い方

今回の章セクション4:XPath Syntax 11. Using XPath with Scrapy 12. Tools to Easily Get XPath 今回の目的Xpathの使い方を学ぶこと 準備以下をコピーするhtml_doc = '''<html> <head> <title>Title of the page</title> </head> <body> <h1>H1 Tag</h1> <h2>H2 Tag with <a href="#">link</a></h2> <p>First Paragraph</p> <p>Second Paragraph</p> </body>…</html>

【Scrapy】簡単なScrapyを作ってみよう2/2  〜Crawlingスクリプトの作成〜

今回の章 セクション3:Building Basic Spider withScrapy 10. Scrapy Simple Spider - Part 3 目次 ①Scrapyの中にspiderの作成 ②結果の確認 ①Scrapyの中にspider(quotes.py)の作成 import scrapy class QuotesSpider(scrapy.Spider): name = 'quotes' allowe…

【Scrapy】簡単なScrapyを作ってみよう1/2  〜Shellで目的のtextを収集する〜

今回の章 セクション3:Building Basic Spider withScrapy 8. Scrapy Simple Spider - Part 1 9. Scrapy Simple Spider - Part 2 今回の目的 quotes.toscrape.comのスパイダーを作る ①H1のtext文字のみ取得 ②Classがtagsになってるもの全ての取得 ③Classがtag…

【Scrapy】初期設定

仮想環境を作る ディレクトリ設定→仮想環境作成→仮想環境に入る $ cd desktop/test$ python3 -m venv venv_0401$ source venv_0401/bin/activate$ cd venv_0401 ScrapyとIpythonをインストールする $ pip install scrapy$ sudo pip install ipython

【Scrapy】目次:Powerful Web Scraping & Crawling with Python

目標 この記事の目標は、初心者でもScrapyを扱う事ができるレベルの記事にする事。単純な講座の要約ではなく、この記事で学べるようになっている。 目次: (Sectionの目次/記事を読むとわかること) 初期設定の方法と →Scrapy vs. Beautiful Soup vs. Sele…