from tkinter import *
import phonenumbers
from phonenumbers import carrier
from phonenumbers import geocoder
from phonenumbers import timezone
from timezonefinder import TimezoneFinder
from geopy.geocoders import Nominatim
from datetime import datetime
import pytz
root=Tk()
root.title('Phone Number Traker')
root.geometry('365x584+400+100')
root.resizable(False,False)
def track():
inserisci_numero=entry.get()
number=phonenumbers.parse(inserisci_numero)
locate=geocoder.description_for_number(number,"IT")
country.config(text=locate)
operator=carrier.name_for_number (number,"it")
sim.config (text=operator)
time = timezone.time_zones_for_number(number)
zona.config(text=time)
geolocator= Nominatim(user_agent="geopiExercises")
location= geolocator.geocode(locate)
lng = location.longitude
lat = location.latitude
longitude.config(text=lng)
latitude.config(text=lat)
obj= TimezoneFinder()
result=obj.timezone_at(lng=location.longitude,lat=location.latitude)
home=pytz.timezone(result)
local_time= datetime.now(home)
current_time=local_time.strftime ("%I:%M:%p")
clock.config(text=current_time)
logo=PhotoImage(file="logo image.png")
Label(root,image=logo).place(x=240,y=70)
Heading = Label(root,text ="Traccia",font=("arial",15,"bold"))
Heading.place(x=90,y=110)
Entry_back= PhotoImage(file="search png.png")
Label (root,image=Entry_back).place(x=20,y=190)
entry=StringVar()
inserisci_numero = Entry(root,textvariable=entry,width=17,bd=0,font=
("arial",20),justify="center")
inserisci_numero.place(x=50,y=220)
Serach_image =PhotoImage(file="search.png")
search =Button(image=Serach_image,borderwidth=0,cursor="hand2",bd=0,font=("arial",16),command=
track)
search.place(x=35,y=300)
Box=PhotoImage(file="bottom png.png")
Label(root,image=Box).place(x=-2,y=355)
country=Label(root,text = "Country: ",bg="#57adff",fg="black",font=("arial",10,"bold"))
country.place(x=50,y=400)
sim=Label(root,text = "SIM: ",bg="#57adff",fg="black",font=("arial",10,"bold"))
sim.place(x=200,y=400)
zona=Label(root,text = "Zona: ",bg="#57adff",fg="black",font=("arial",10,"bold"))
zona.place(x=50,y=450)
clock=Label(root,text = "Phone Time: ",bg="#57adff",fg="black",font=("arial",10,"bold"))
clock.place(x=200,y=450)
longitude=Label(root,text = "Longitudine: ",bg="#57adff",fg="black",font=("arial",10,"bold"))
longitude.place(x=50,y=500)
latitude=Label(root,text = "Latitudine: ",bg="#57adff",fg="black",font=("arial",10,"bold"))
latitude.place(x=200,y=500)
root.mainloop()
when I start the application I can't see on the screen, neither the
country nor the position. what did i do wrong? using pytnon 3.10. I
am going crazy
Related
I am trying to have a properly formated date in bokeh when using hovertool and ploting data from a pandas dataframe. I think I tried all solution I have seen proposed around but none is working. With the example code below, I obtain this:
import pandas as pd
import datetime
from datetime import datetime
from bokeh.plotting import figure, show, gridplot
from bokeh.io import output_notebook, push_notebook
from bokeh.models.formatters import DatetimeTickFormatter
from bokeh.models import ColumnDataSource
from bokeh.models.tools import HoverTool
from bokeh.models import LinearAxis, Range1d
output_notebook()
data = [["2022-08-05", 25,545,1],["2022-08-06",33,543,0],["2022-08-07",17,542,1]]
df_test = pd.DataFrame(data, columns=['Date','sum','size','present'])
df4 = df_test.set_index('Date')
df4.index = pd.to_datetime(df4.index)
Source = ColumnDataSource(data={'date' : df4.index,
'percent' : 100*df4['sum']/df4['size']})
hover = HoverTool(tooltips = [('Date', '#date'),('Percent', '#percent')],
formatters = {'#date' : 'datetime'}, mode='vline')
f2 = figure(plot_height=400, plot_width=800,x_axis_label="Date",y_axis_label="Pourcentage de grises",\
x_axis_type="datetime")
l1 = f2.circle(x = 'date',y = "percent", source=Source, line_width=4,color="sandybrown",legend_label='% gris',
)
f2.legend.location = "top_right"
f2.legend.click_policy="hide"
f2.add_tools(hover)
show(f2)
Percentage(%) is a format, therefore we don't multiply 100,
#date{%F} is equivalent to #date{%Y-%m-%d}
Source = ColumnDataSource(data={'date' : df4.index,
'percent' : df4['sum']/df4['size']})
hover = HoverTool(tooltips = [('Date', '#date{%F}'),('Percent', '#percent{%0.2f}')],
formatters = {'#date' : 'datetime'}, mode='vline')
from bokeh.models.formatters import NumeralTickFormatter
f2.yaxis.formatter = NumeralTickFormatter(format='0.00 %')
Is there a way to display a pandas DataFrame in KivyMD? I tried putting the dataframe as a KivyMD DataTable but it doesn't work that way.
You could use the MDDataTable and fill the row with the dataframe. You only need to process the data. Try to define a function to do that:
def get_data_table(dataframe):
column_data = list(dataframe.columns)
row_data = dataframe.to_records(index=False)
return column_data, row_data
Then you can put all into the MDDataTable after setting the size of columns.
import pandas as pd
from kivy.uix.anchorlayout import AnchorLayout
from kivymd.app import MDApp
from kivy.lang.builder import Builder
from kivymd.uix.datatables import MDDataTable
from kivy.metrics import dp
dataframe = pd.read_csv(filename)
class MyApp(MDApp):
def build(self):
layout = AnchorLayout()
container = my_root.ids.container
print(container)
column_data, row_data = get_data_table(dataframe)
column_data = [(x, dp(60)) for x in column_data]
table = MDDataTable(
column_data = column_data,
row_data = row_data,
use_pagination=True
)
layout.add_widget(table)
return layout
MyApp().run()
I have a piece of code. I am able to view all the values, but when it comes to updating the newly linked issue's Tempo "Account" field, nothing happens. I am using Scriptrunner For Jira's custom listener
I would expect the newly linked issue (issueInEpic) to have it's Tempo "Account" field (linkedField) value (oldCfValue) updated with the value (newCfValue) of the Epic's "Account" field value.
log.info() shows all of the values properly. The only issue is updating the linked issue.
import com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.IssueChangeHolder
def log = Logger.getLogger(com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent)
log.setLevel(Level.INFO)
if ([IssueLinkCreatedEvent].contains(event.getClass())) {
if (event.issueLink.issueLinkType.name == "Epic-Story Link") {
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issueManager = ComponentAccessor.getIssueManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def accountField = cfManager.getCustomFieldObjects(event.issueLink.sourceObject)?.find{it.name == "Account"}
def linkedField = cfManager.getCustomFieldObjects(event.issueLink.destinationObject)?.find{it.name == "Account"}
MutableIssue issueInEpic = event.issueLink.destinationObject as MutableIssue
MutableIssue epic = event.issueLink.sourceObject as MutableIssue
def newCfValue = accountField.getValue(epic)
def oldCfValue = linkedField.getValue(issueInEpic)
issueInEpic.setCustomFieldValue(linkedField, newCfValue)
issueManager.updateIssue(currentUser, issueInEpic, EventDispatchOption.DO_NOT_DISPATCH, false)
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService.class)
def wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
issueIndexingService.reIndex(event.issueLink.destinationObject)
ImportUtils.setIndexIssues(wasIndexing)
log.info(accountField)
log.info(newCfValue)
log.info(oldCfValue)
log.info(issueInEpic)
log.info(epic)
log.info(linkedField)
}
}
I'm creating a bokeh application that pulls data from Quandl stock prices and changes the plot based the stock symbol the user inputs. I used an example from this bokeh tuorial as a model.
Everything is working except the plot won't update when I input a new symbol.
I've tried passing the new data as a dictionary (before I was just passing a DataFrame to ColumnDataSource(), but no luck.
import pandas as pd
import numpy as np
from bokeh.models.widgets import TextInput, Select
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.layouts import column, row
from bokeh.io import show, output_notebook
import quandl
This is the function to get the data:
def get_data(symbol):
dictionary = {}
data = quandl.get('WIKI/' + symbol, collapse = 'annual', returns='numpy')
df = pd.DataFrame(data)
dictionary['date'] = list(df.Date.values)
dictionary['high'] = list(df.High.values)
return dictionary
And this is a function for the plot:
def modify_doc(doc):
symbol = 'AAWW'
source = ColumnDataSource(data = get_data(symbol))
p = figure(x_axis_type='datetime', title='Stock Price', plot_height=350, plot_width=800)
p.xgrid.grid_line_color=None
p.ygrid.grid_line_alpha=0.5
p.xaxis.axis_label = 'year'
p.yaxis.axis_label = 'close'
r = p.line(source.data['date'],
source.data['high'],
line_color = 'navy')
select = Select(title="Color", value="navy", options=COLORS)
input = TextInput(title="Ticker Symbol", value=symbol)
def update_symbol(attrname, old, new):
source.data = get_data(input.value)
input.on_change('value', update_symbol)
layout = column(row(input, width=400), row(p))
doc.add_root(layout)
show(modify_doc)
I would think that the plot would update when the new symbol is entered, but it just stays the same.
Any thoughts?
Your code looks like Bokeh server application but you use show() what doesn't look good to me. You are also trying to update the figure by assigning new data to the source but you did not pass your source to the figure object so it won't have any effect. Could you try if this code works for you? (should work for Bokeh v1.0.4)
import random
import pandas as pd
from tornado.ioloop import IOLoop
from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.application.handlers.function import FunctionHandler
from bokeh.plotting import figure, ColumnDataSource
from bokeh.models.widgets import TextInput
from bokeh.layouts import column, row
def make_document(doc):
symbol = 'AAWW'
def get_data(symbol):
dictionary = {}
data = quandl.get('WIKI/' + symbol, collapse = 'annual', returns = 'numpy')
df = pd.DataFrame(data)
dictionary['date'] = list(df.Date.values)
dictionary['high'] = list(df.High.values)
return dictionary
source = ColumnDataSource(data = get_data(symbol))
p = figure(x_axis_type = 'datetime', title = 'Stock Price', plot_height = 350, plot_width = 800)
p.xgrid.grid_line_color = None
p.ygrid.grid_line_alpha = 0.5
p.xaxis.axis_label = 'year'
p.yaxis.axis_label = 'close'
r = p.line(x = 'date',
y = 'high',
source = source,
line_color = 'navy')
input = TextInput(title = "Ticker Symbol", value = symbol)
def update_symbol(attrname, old, new):
source.data = get_data(input.value)
input.on_change('value', update_symbol)
layout = column(row(input, width = 400), row(p))
doc.add_root(layout)
io_loop = IOLoop.current()
server = Server({'/myapp': Application(FunctionHandler(make_document))}, port = 5001, io_loop = io_loop)
server.start()
server.show('/myapp')
io_loop.start()
Basically the main change is here:
r = p.line(x = 'date',
y = 'high',
source = source,
line_color = 'navy')
Based on the answer I got from Tony, I just had to change one line of code:
r = p.line(x = 'date',
y = 'high',
source = source,
line_color = 'navy')
My goal here was to create a Bokeh widgetbox which you could use to provide input to a form, however the only widgets that allow me to get my inputs back from Bokeh's javascript side into Python variables are RadioButtonGroups. Otherwise, Multiselect, AutocompleteInput, and others are ONLY able to return my input if it's in the form of an integer. This is being done in a Jupyter NB using Python and Bokeh 0.13.0, if you happen to have any questions or I've left anything out please don't hesitate to let me know.
Please see code below:
import os, time, sys
from bokeh.layouts import widgetbox
from bokeh.models.widgets import RadioButtonGroup, Button, TextInput
from bokeh.models.widgets.inputs import MultiSelect
from bokeh.models.widgets import AutocompleteInput
from bokeh.models.callbacks import CustomJS
from bokeh.io import output_notebook, show
from bokeh.models import ColumnDataSource
from bokeh.models.widgets.markups import Div
from bokeh.resources import INLINE
output_notebook(resources=INLINE)
ipies=[str(i.strip('.ipynb')) for i in os.listdir() if i.endswith('.ipynb')]
minutes=0
hours=0
days=0
months=0
daysmonth=0
days=0
minute_options=[str(i) for i in range(1,60)]
minute_options.append("*")
minute_callback = CustomJS(args=dict(a=minute_options), code="""
var options=a;
console.log(options[parseInt(cb_obj.active)]);
var ind=options[parseInt(cb_obj.active)];
IPython.notebook.kernel.execute('minutes='+ind+'');
""")
minute_rbg = RadioButtonGroup(
labels=minute_options, callback=minute_callback, active=len(minute_options)-1)
min_title=Div(text="Which minute on the hour, * for every minute")
hour_options=[str(i) for i in range(24)]
hour_options.append("*")
hour_callback = CustomJS(args=dict(a=hour_options), code="""
var options=a;
console.log(options[parseInt(cb_obj.active)]);
var ind=options[parseInt(cb_obj.active)];
IPython.notebook.kernel.execute('hours='+ind+'');
""")
hour_rbg = RadioButtonGroup(
labels=hour_options,callback=hour_callback,active=len(hour_options)-1)
hour_title=Div(text="Which hour in a day, * for every hour")
day_month_options=[str(i) for i in range(1,32)]
day_month_options.append("*")
day_month_callback = CustomJS(args=dict(a=day_month_options), code="""
var options=a;
console.log(options[parseInt(cb_obj.active)]);
var ind=options[parseInt(cb_obj.active)];
IPython.notebook.kernel.execute('daysmonth='+ind+'');
""")
day_month_rbg = RadioButtonGroup(
labels=day_month_options,callback=day_month_callback,active=len(day_month_options)-1)
day_month_title=Div(text="Which day in a month, * for every day of the month")
month_options=[str(i) for i in range(1,13)]
month_options.append("*")
month_callback = CustomJS(args=dict(a=month_options), code="""
var options=a;
console.log(options[parseInt(cb_obj.active)]);
var ind=options[parseInt(cb_obj.active)];
IPython.notebook.kernel.execute('months='+ind+'');
""")
month_rbg = RadioButtonGroup(
labels=month_options, callback=month_callback,active=len(month_options)-1)
month_title=Div(text="Which month in a year, * for every month")
day_week_options=[str(i) for i in range(7)]
day_week_options.append("*")
day_week_callback = CustomJS(args=dict(a=day_week_options), code="""
var options=a;
console.log(options[parseInt(cb_obj.active)]);
var ind=options[parseInt(cb_obj.active)];
IPython.notebook.kernel.execute('days='+ind+'');
""")
day_week_rbg = RadioButtonGroup(
labels=day_week_options, callback=day_week_callback, active=len(day_week_options)-1)
days_week_title=Div(text="Which day in a week, * for every day of the week")
import pandas as pd
ipies_pd = pd.DataFrame({"a":ipies})
#Selection source: IPIES CDS
cds = ColumnDataSource(data=ipies_pd)
#Selection source: autocompleteinput & multiselect widgets
selection_callback = CustomJS(args=dict(source=cds), code="""
// THIS CALLBACK ONLY BRINGS BACK SELECTIONS IF THEY ARE INTEGERS
var cbobj = cb_obj.value;
IPython.notebook.kernel.execute("auto_c_value = "\"+ cbobj + "\");
""")
ms = MultiSelect(title="power", callback=selection_callback, options=ipies)
auto_c=AutocompleteInput(completions=ipies, height=100, callback=selection_callback)
button_callback = CustomJS(code="""
var cur_index = IPython.notebook.get_selected_index()+1;
var end_index=IPython.notebook.ncells();
IPython.notebook.execute_cell_range(IPython.notebook.get_selected_index()+1, IPython.notebook.ncells());
""")
button = Button(label="button~!", button_type="primary", callback=button_callback)
w_box = widgetbox(min_title, minute_rbg, hour_title, hour_rbg, day_month_title, day_month_rbg,
month_title, month_rbg,days_week_title, day_week_rbg, button,
ms, auto_c, width=800, sizing_mode='scale_both')
show(w_box)