質問編集履歴

1

ソースコードを訂正

2021/12/08 09:19

投稿

HukahukaMask
HukahukaMask

スコア1

test CHANGED
File without changes
test CHANGED
@@ -32,6 +32,8 @@
32
32
 
33
33
  from apiclient.discovery import build
34
34
 
35
+
36
+
35
37
  API_KEY = "ここにAPIキー"
36
38
 
37
39
  KEY_WORD = "検索ワード"
@@ -54,6 +56,10 @@
54
56
 
55
57
 
56
58
 
59
+ pA ="2021-11-01T00:00:00Z"
60
+
61
+ pB ="2021-12-01T00:00:00Z"
62
+
57
63
  def youtube_search():
58
64
 
59
65
  search_response = youtube.search().list(
@@ -66,11 +72,13 @@
66
72
 
67
73
  order=ORDER,
68
74
 
69
- publishedBefore="2021-05-01T00:00:00Z",
75
+ publishedBefore=pB,
70
76
 
71
- publishedAfter="2021-04-01T00:00:00Z"
77
+ publishedAfter=pA
72
78
 
73
79
  ).execute()
80
+
81
+
74
82
 
75
83
  videos = []
76
84
 
@@ -80,11 +88,15 @@
80
88
 
81
89
  view_count = get_view_count(search_result["id"]["videoId"])
82
90
 
83
- videos.append("%s" %(search_result["snippet"]["title"]))
91
+ videos.append("%s,%s,%s,https://www.youtube.com/watch?v=%s,%s," % (pA,pB,view_count.rjust(10), search_result["id"]["videoId"],
84
92
 
93
+ search_result["snippet"]["title"]))
94
+
85
- with open('dougatitle.csv', 'w',encoding='utf_8_sig') as f:
95
+ with open('dougatitle.csv', 'a',encoding='utf_8_sig') as f:
86
96
 
87
97
  print("\n".join(videos),file=f)
98
+
99
+
88
100
 
89
101
  if __name__ == "__main__":
90
102