2 # -*- coding: utf-8 -*-
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the Revised BSD License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 Revised BSD License for more details.
13 Copyright 2020 Cool Dude 2k - http://idb.berlios.de/
14 Copyright 2020 Game Maker 2k - http://intdb.sourceforge.net/
15 Copyright 2020 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
17 $FileInfo: pyopencnam-ui.py - Last Update: 1/20/2020 Ver. 1.2.0 RC 1 - Author: cooldude2k $
20 from __future__
import absolute_import
, division
, print_function
, unicode_literals
, generators
, with_statement
, nested_scopes
28 from ConfigParser
import SafeConfigParser
30 from configparser
import SafeConfigParser
39 import tkinter
as Tkinter
40 from tkinter
import messagebox
as tkMessageBox
41 from tkinter
import filedialog
as tkFileDialog
42 from tkinter
import colorchooser
as tkColorChooser
43 from tkinter
import simpledialog
as tkSimpleDialog
50 __program_name__
= "PyOpenCNAM"
51 __project__
= __program_name__
52 __project_url__
= "https://github.com/GameMaker2k/PyOpenCNAM"
53 __version_info__
= (1, 2, 0, "RC 1", 1)
54 __version_date_info__
= (2020, 1, 20, "RC 1", 1)
55 __version_date__
= str(__version_date_info__
[0])+"."+str(__version_date_info__
[
56 1]).zfill(2)+"."+str(__version_date_info__
[2]).zfill(2)
58 if(__version_info__
[4] != None):
59 __version_date_plusrc__
= __version_date__
+ \
60 "-"+str(__version_date_info__
[4])
61 if(__version_info__
[4] == None):
62 __version_date_plusrc__
= __version_date__
63 if(__version_info__
[3] != None):
64 __version__
= str(__version_info__
[0])+"."+str(__version_info__
[1])+"."+str(
65 __version_info__
[2])+" "+str(__version_info__
[3])
66 if(__version_info__
[3] == None):
68 __version_info__
[0])+"."+str(__version_info__
[1])+"."+str(__version_info__
[2])
70 geturls_ua_pyopencnam_python
= "Mozilla/5.0 (compatible; {proname}/{prover}; +{prourl})".format(
71 proname
=__project__
, prover
=__version__
, prourl
=__project_url__
)
72 if(platform
.python_implementation() != ""):
73 geturls_ua_pyopencnam_python_alt
= "Mozilla/5.0 (compatible; {osver}; {archtype}; +{prourl}) {pyimp}/{pyver} (KHTML, like Gecko) {proname}/{prover}".format(osver
=platform
.system(
74 )+" "+platform
.release(), archtype
=platform
.machine(), prourl
=__project_url__
, pyimp
=platform
.python_implementation(), pyver
=platform
.python_version(), proname
=__project__
, prover
=__version__
)
75 if(platform
.python_implementation() == ""):
76 geturls_ua_pyopencnam_python_alt
= "Mozilla/5.0 (compatible; {osver}; {archtype}; +{prourl}) {pyimp}/{pyver} (KHTML, like Gecko) {proname}/{prover}".format(osver
=platform
.system(
77 )+" "+platform
.release(), archtype
=platform
.machine(), prourl
=__project_url__
, pyimp
="Python", pyver
=platform
.python_version(), proname
=__project__
, prover
=__version__
)
79 master_phone_number
= "+16786318356"
80 master_account_sid
= None
81 master_auth_token
= None
82 master_service_level
= "standard"
84 if(os
.path
.exists("pyopencnam.ini") and os
.path
.isfile("pyopencnam.ini")):
85 cfgparser
= SafeConfigParser()
86 cfgparser
.read("pyopencnam.ini")
87 master_phone_number
= cfgparser
.get("OpenCNAM", "phone_number")
88 master_account_sid
= cfgparser
.get("OpenCNAM", "account_sid")
89 if(len(master_account_sid
) <= 0):
90 master_account_sid
= None
91 master_auth_token
= cfgparser
.get("OpenCNAM", "auth_token")
92 if(len(master_auth_token
) <= 0):
93 master_auth_token
= None
94 master_opencnam_url
= cfgparser
.get("OpenCNAM", "opencnam_url")
95 master_service_level
= cfgparser
.get("OpenCNAM", "service_level")
99 queryresult
.delete(0.0, END
)
100 opencnam_queryresult
= pyopencnam
.query_cnam_info(phonenumber
.get(
101 ), accountsid
.get(), authtoken
.get(), master_opencnam_url
, servicelevel
.get(ACTIVE
))
102 print(opencnam_queryresult
)
103 opencnam_result
= "{\n \"name\": \""+str(opencnam_queryresult
['name'])+"\",\n \"number\": \""+str(
104 opencnam_queryresult
['number'])+"\",\n \"price\": "+str(opencnam_queryresult
['price'])+",\n \"uri\": \""+str(opencnam_queryresult
['uri'])+"\"\n}\n"
105 queryresult
.insert(END
, opencnam_result
)
110 root
.geometry("400x440")
111 root
.resizable(width
=False, height
=False)
112 root
.title(str(__program_name__
)+" Query Tool "+str(__version__
))
113 root
.iconbitmap('pyopencnam-16x.ico')
115 phonenumber_label
= Label(root
, text
="Phone Number", height
=1)
116 phonenumber_label
.pack(side
=TOP
, anchor
="w")
117 phonenumber
= Entry(root
, textvariable
=StringVar(
118 root
, value
=master_phone_number
), width
=65)
119 phonenumber
.pack(side
=TOP
, anchor
="w")
121 accountsid_label
= Label(root
, text
="Account SID", height
=1)
122 accountsid_label
.pack(side
=TOP
, anchor
="w")
123 accountsid
= Entry(root
, textvariable
=StringVar(
124 root
, value
=master_account_sid
), width
=65)
125 accountsid
.pack(side
=TOP
, anchor
="w")
127 authtoken_label
= Label(root
, text
="Auth Token", height
=1)
128 authtoken_label
.pack(side
=TOP
, anchor
="w")
129 authtoken
= Entry(root
, textvariable
=StringVar(
130 root
, value
=master_auth_token
), width
=65)
131 authtoken
.pack(side
=TOP
, anchor
="w")
133 opencnamurl_label
= Label(root
, text
="OpenCNAM URL", height
=1)
134 opencnamurl_label
.pack(side
=TOP
, anchor
="w")
135 opencnamurl
= Entry(root
, textvariable
=StringVar(
136 root
, value
=master_opencnam_url
), width
=65)
137 opencnamurl
.pack(side
=TOP
, anchor
="w")
139 service_level
= reversed(["standard", "value", "plus"])
140 servicelevel_label
= Label(root
, text
="Service Level", height
=1)
141 servicelevel_label
.pack(side
=TOP
, anchor
="w")
142 servicelevel
= Listbox(root
, width
=65, height
=2)
143 for item
in service_level
:
144 servicelevel
.insert(0, item
)
145 servicelevel
.pack(side
=TOP
, anchor
="w")
146 if(master_service_level
== "standard"):
147 servicelevel
.select_set(0)
148 elif(master_service_level
== "plus"):
149 servicelevel
.select_set(1)
151 servicelevel
.select_set(0)
153 button
= Button(root
, text
="Run CNAM Query", command
=QueryCNAM
)
154 button
.pack(pady
=20, padx
=20)
156 queryresult_label
= Label(root
, text
="Query Result", height
=1)
157 queryresult_label
.pack(side
=TOP
, anchor
="w")
158 queryresult
= Text(root
, height
=8, width
=49)
159 queryresult
.pack(side
=TOP
, anchor
="w")
160 queryresult
.delete(0.0, END
)