Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def settz(self, ctx, *, tz : str = None):
"""Sets your TimeZone - Overrides your UTC offset - and accounts for DST."""
usage = 'Usage: `{}settz [Region/City]`\nYou can get a list of available TimeZones with `{}listtz`'.format(ctx.prefix, ctx.prefix)
if not tz:
self.settings.setGlobalUserStat(ctx.author, "TimeZone", None)
await ctx.channel.send("*{}*, your TimeZone has been removed!".format(DisplayName.name(ctx.author)))
return
not_found = 'TimeZone `{}` not found!'.format(tz.replace('`', '\\`'))
# Let's get the timezone list
tz_list = FuzzySearch.search(tz, pytz.all_timezones, None, 3)
if not tz_list[0]['Ratio'] == 1:
# Setup and display the picker
msg = not_found + '\nSelect one of the following close matches:'
index, message = await PickList.Picker(
title=msg,
list=[x["Item"] for x in tz_list],
ctx=ctx
).pick()
# Check if we errored/cancelled
if index < 0:
await message.edit(content=not_found)
return
# We got a time zone
self.settings.setGlobalUserStat(ctx.author, "TimeZone", tz_list[index]['Item'])
await message.edit(content="TimeZone set to `{}`!".format(tz_list[index]['Item']))
return
self.output_channel_changed = False
self.telescope_changed = False
self.camera_automation_changed = False
self.tesselation_changed = False
# Remember if the ASCOM or INDI configuration editor was called. Changes made by this
# editor are only applied in the end if the user accepts the changes in the main window.
self.ascomeditor = None
self.ascomeditor_called = False
self.indieditor = None
self.indieditor_called = False
# Start filling the text fields of the GUI.
self.input_longitude.setText(self.c.conf.get("Geographical Position", "longitude"))
self.input_latitude.setText(self.c.conf.get("Geographical Position", "latitude"))
self.input_elevation.setText(self.c.conf.get("Geographical Position", "elevation"))
self.timezone_chooser.addItems(all_timezones)
self.timezone_chooser.setCurrentIndex(
all_timezones.index(self.c.conf.get("Geographical Position", "timezone")))
# Special treatment of available camera models: populate the camera_chooser with list.
camlist = self.c.get_camera_list()
self.camera_chooser.addItems(camlist)
self.camera_chooser.setCurrentIndex(camlist.index(self.c.conf.get("Camera", "name")))
self.input_ip_address.setText(self.c.conf.get("Camera", "ip address"))
self.input_focal_length.setText(self.c.conf.get("Telescope", "focal length"))
# Prepare for alternative telescope interfaces (e.g. INDI).
interface_list = ["ASCOM", "INDI"]
self.mount_interface_chooser.addItems(interface_list)
self.mount_interface_chooser.setCurrentIndex(
interface_list.index(self.c.conf.get("Telescope", "interface type")))
"schedules": {
"available": 100
},
"sensors": {
"available": 63,
"clip": {
"available": 63
},
"zgp": {
"available": 63
},
"zll": {
"available": 63
}
},
"timezones": pytz.all_timezones,
}
REGISTRY_BASE_CONFIG = {
"name": "Philips hue",
"zigbeechannel": 25,
# bridgeid":"001788FFFE29864E",
# mac":"00:17:88:29:85:3e",
"dhcp": True,
# "ipaddress":"192.168.10.11",
# "netmask":"255.255.255.0",
# "gateway":"192.168.10.1",
"proxyaddress": "none",
"proxyport": 0,
"UTC": "2018-06-09T18:03:20",
"localtime": "2018-06-09T21:03:20",
# "timezone":"Europe/Bucharest",
import pytz
import datetime
from django.conf import settings
from django import forms
from timezones.utils import adjust_datetime_to_timezone
ALL_TIMEZONE_CHOICES = tuple(zip(pytz.all_timezones, pytz.all_timezones))
COMMON_TIMEZONE_CHOICES = tuple(zip(pytz.common_timezones, pytz.common_timezones))
PRETTY_TIMEZONE_CHOICES = []
for tz in pytz.common_timezones:
now = datetime.datetime.now(pytz.timezone(tz))
PRETTY_TIMEZONE_CHOICES.append((tz, "(GMT%s) %s" % (now.strftime("%z"), tz)))
class TimeZoneField(forms.ChoiceField):
def __init__(self, choices=None, max_length=None, min_length=None,
*args, **kwargs):
self.max_length, self.min_length = max_length, min_length
if choices is not None:
kwargs["choices"] = choices
else:
kwargs["choices"] = PRETTY_TIMEZONE_CHOICES
super(TimeZoneField, self).__init__(*args, **kwargs)
origin = StringType(regex='(-?\d+(\.\d+)?),(-?\d+(\.\d+)?)', required=True)
offset = StringType(regex='\d+(\.\d+)?(cm|m|km|in|ft|mi)')
scale = StringType(regex='\d+(\.\d+)?(cm|m|km|in|ft|mi)')
decay = FloatType()
class DateTimeRange(Model):
class Options:
serialize_when_none = False
gt = DateTimeType()
gte = DateTimeType()
lt = DateTimeType()
lte = DateTimeType()
tz = StringType(choices=pytz.all_timezones)
class FloatRange(Model):
class Options:
serialize_when_none = False
gt = FloatType()
gte = FloatType()
lt = FloatType()
lte = FloatType()
class IntRange(Model):
class Options:
if request.user.auto_watch:
for poll in polls.filter(Q(vote__user=request.user)):
try:
poll_watch = PollWatch(poll=poll, user=request.user)
poll_watch.save()
except IntegrityError:
pass
user_form = BitpollUserSettingsForm(instance=request.user)
return TemplateResponse(request, 'base/settings.html', {
'polls': polls,
'user': request.user,
'user_form': user_form,
'languages': USER_LANG,
'timezones': all_timezones,
})
from django.utils.translation import ugettext_lazy as _
# App
from timezone_utils import forms
__all__ = ('TimeZoneField', 'LinkedTZDateTimeField')
# =============================================================================
# MODEL FIELDS
# =============================================================================
class TimeZoneField(CharField):
# Enforce the minimum length of max_length to be the length of the longest
# pytz timezone string
MIN_LENGTH = max(map(len, pytz.all_timezones))
default_error_messages = {
'invalid': _("'%(value)s' is not a valid time zone."),
}
# pylint: disable=newstyle
def __init__(self, *args, **kwargs):
# Retrieve the model field's declared max_length or default to pytz's
# maximum length
declared_max_length = kwargs.get('max_length', self.MIN_LENGTH)
# Set the max length to the highest value between the timezone maximum
# length and the declared max_length
kwargs['max_length'] = max(declared_max_length, self.MIN_LENGTH)
# Warn that we changed the value of max_length so that they can
if declared_max_length and declared_max_length != kwargs['max_length']:
from __future__ import absolute_import
from __future__ import unicode_literals
from datetime import datetime
import pytz
from six.moves import zip
from six.moves import range
ALL_TIMEZONE_CHOICES = tuple(zip(pytz.all_timezones, pytz.all_timezones))
COMMON_TIMEZONE_CHOICES = tuple(zip(pytz.common_timezones, pytz.common_timezones))
PRETTY_TIMEZONE_CHOICES = []
for tz in pytz.common_timezones:
now = datetime.now(pytz.timezone(tz))
ofs = now.strftime("%z")
PRETTY_TIMEZONE_CHOICES.append((int(ofs), tz, "(GMT%s) %s" % (ofs, tz)))
PRETTY_TIMEZONE_CHOICES.sort()
for i in range(len(PRETTY_TIMEZONE_CHOICES)):
PRETTY_TIMEZONE_CHOICES[i] = PRETTY_TIMEZONE_CHOICES[i][1:]
# Cast the timezone choices to a tuple and return
return tuple(choices)
# ==============================================================================
# CHOICES CONSTANTS
# ==============================================================================
# Standard (unaltered) pytz timezone choices
ALL_TIMEZONES_CHOICES = tuple(zip(pytz.all_timezones, pytz.all_timezones))
COMMON_TIMEZONES_CHOICES = tuple(
zip(pytz.common_timezones, pytz.common_timezones)
)
# Grouped by timezone offset, with "GMT-05:00" as the group name
GROUPED_ALL_TIMEZONES_CHOICES = get_choices(
timezones=pytz.all_timezones,
grouped=True
)
GROUPED_COMMON_TIMEZONES_CHOICES = get_choices(
timezones=pytz.common_timezones,
grouped=True
)
# Sorted by timezone offset, with "(GMT-05:00) US/Eastern" as the display name
PRETTY_ALL_TIMEZONES_CHOICES = get_choices(timezones=pytz.all_timezones)
PRETTY_COMMON_TIMEZONES_CHOICES = get_choices(timezones=pytz.common_timezones)
model = Schedule
fields = ('programme', 'calendar', 'type')
programme = django_filters.CharFilter(field_name="programme__slug")
class ScheduleViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.DjangoModelPermissionsOrAnonReadOnly,)
queryset = Schedule.objects.all()
filter_backends = (filters.DjangoFilterBackend, filters.OrderingFilter)
filter_class = ScheduleFilter
serializer_class = serializers.ScheduleSerializer
class TimezoneForm(forms.Form):
timezone = forms.ChoiceField(required=False, choices=[(x, x) for x in pytz.all_timezones])
def clean_timezone(self):
timezone = self.cleaned_data.get('timezone')
if timezone:
return pytz.timezone(timezone)
return timezone
class TransmissionForm(TimezoneForm):
after = forms.DateField()
before = forms.DateField()
calendar = forms.CharField(required=False)
def clean(self):
cleaned_data = super(TransmissionForm, self).clean()
if cleaned_data.get('before') and cleaned_data.get('after'):