summaryrefslogtreecommitdiff
path: root/vvv.py
blob: 3605700db91f7640e7734b64dea5fb2c36b67272 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import os
import json
import time
import requests
import praw
from tkinter import *
import tkinter as tk

class pageindex(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

     

        # the container is where we'll stack a bunch of frames
        # on top of each other, then the one we want visible
        # will be raised above the others
        container = tk.Frame(self)
        #container.pack(side="top", fill="both", expand=True)
        container.grid(row=1, rowspan=2, column=1, columnspan=2)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        self.frames = {}
        for F in (ytscbyname, ytscbyid, PageTwo):
            page_name = F.__name__
            frame = F(parent=container, controller=self)
            self.frames[page_name] = frame

            # put all of the pages in the same location;
            # the one on the top of the stacking order
            # will be the one that is visible.
            frame.grid(row=0, column=0, sticky="nsew")

        self.show_frame("ytscbyname")

    def show_frame(self, page_name):
        '''Show a frame for the given page name'''
        frame = self.frames[page_name]
        frame.tkraise()

class ytscbyname(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        self.configure(background="#323232")
        def Youtube_stats():
            channel = ytuser.get()
            r = requests.get('https://www.googleapis.com/youtube/v3/channels?part=statistics&forUsername='+channel+'&key=AIzaSyDdh94NZll6tzTUmO17d5nrh0zMuKcajaw')
            j = r.json()
            subs = j['items'][0]['statistics']['subscriberCount']
            views = j['items'][0]['statistics']['viewCount']
            ytsubs.config(text="{:,}".format(int(subs)))
            ytviews.config(text="{:,}".format(int(views)))
        def Ytreset():
            ytsubs.config(text="")
            ytviews.config(text="")
      

        ytlabel = tk.Label(self, text="Youtube channel Stats by Name", bg="#323232", fg="white", font="none 15 bold")
        ytuser = tk.Entry(self)
        ytgo = tk.Button(self, text="GO", bg="green", command=Youtube_stats)
        ytreset = tk.Button(self, text="Reset", bg="red", command=Ytreset)
        ytsublabel = tk.Label(self, text="Total subs:", bg="#323232", fg="white", font="none 15")
        ytviewslabel = tk.Label(self, text="Total Views:", bg="#323232", fg="white", font="none 15")
        ytsubs = tk.Label(self, text="", bg="#323232", fg="white", font="none 15")
        ytviews = tk.Label(self, text="", bg="#323232", fg="white", font="none 15")

        menu = tk.Menu(self.master)
        self.master.config(menu=menu)
        YoutubeSubCounter = tk.Menu(menu)
        YoutubeSubCounter.add_command(label="Youtube channel Stats by Name", command=lambda: controller.show_frame("ytscbyname"))
        YoutubeSubCounter.add_command(label="Youtube channel Stats by ID", command=lambda: controller.show_frame("ytscbyid"))
        menu.add_cascade(label="Youtube Channel Stats", menu=YoutubeSubCounter)
        
        ytlabel.grid(row=1, column=1, columnspan=2)
        ytuser.grid(row=2, column=1, columnspan=2)
        ytgo.grid(row=3, column=1, sticky="E")
        ytreset.grid(row=3, column=2, sticky="W")
        ytsublabel.grid(row=4, column=1)
        ytsubs.grid(row=4, column=2)
        ytviewslabel.grid(row=5, column=1)
        ytviews.grid(row=5, column=2)


        

        button1 = tk.Button(self, text="Go to Page One",
                            command=lambda: controller.show_frame("ytscbyid"))
        button2 = tk.Button(self, text="Go to Page Two",
                            command=lambda: controller.show_frame("PageTwo"))
        button1.grid(row=6, column=1)
        button2.grid(row=6, column=2)

        
class ytscbyid(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        self.configure(background="#323232")
        def Youtube_stats():
            ytid = ytuser.get()
            r = requests.get('https://www.googleapis.com/youtube/v3/channels?part=statistics&id='+ytid+'&key=AIzaSyDdh94NZll6tzTUmO17d5nrh0zMuKcajaw')
            j = r.json()
            subs = j['items'][0]['statistics']['subscriberCount']
            views = j['items'][0]['statistics']['viewCount']
            ytsubs.config(text="{:,}".format(int(subs)))
            ytviews.config(text="{:,}".format(int(views)))
        def Ytreset():
            ytsubs.config(text="")
            ytviews.config(text="")
      

        ytlabel = tk.Label(self, text="Youtube channel Stats by channel ID", bg="#323232", fg="white", font="none 15 bold")
        ytuser = tk.Entry(self)
        ytgo = tk.Button(self, text="GO", bg="green", command=Youtube_stats)
        ytreset = tk.Button(self, text="Reset", bg="red", command=Ytreset)
        ytsublabel = tk.Label(self, text="Total subs:", bg="#323232", fg="white", font="none 15")
        ytviewslabel = tk.Label(self, text="Total Views:", bg="#323232", fg="white", font="none 15")
        ytsubs = tk.Label(self, text="", bg="#323232", fg="white", font="none 15")
        ytviews = tk.Label(self, text="", bg="#323232", fg="white", font="none 15")

        ytlabel.grid(row=1, column=1, columnspan=2)
        ytuser.grid(row=2, column=1, columnspan=2)
        ytgo.grid(row=3, column=1, sticky="E")
        ytreset.grid(row=3, column=2, sticky="W")
        ytsublabel.grid(row=4, column=1)
        ytsubs.grid(row=4, column=2)
        ytviewslabel.grid(row=5, column=1)
        ytviews.grid(row=5, column=2)


        

        button1 = tk.Button(self, text="Go to Page One",
                            command=lambda: controller.show_frame("ytscbyname"))
        button2 = tk.Button(self, text="Go to Page Two",
                            command=lambda: controller.show_frame("PageTwo"))
        button1.grid(row=6, column=1)
        button2.grid(row=6, column=2)
class PageTwo(tk.Frame):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        self.controller = controller
        label = tk.Label(self, text="This is page 2")
        label.pack(side="top", fill="x", pady=10)
        button = tk.Button(self, text="Go to the start page",
                           command=lambda: controller.show_frame("ytscbyid"))
        button.pack()


if __name__ == "__main__":
    app = pageindex()
    app.mainloop()