本文整理匯總了Python中maya.parse方法的典型用法代碼示例。如果您正苦於以下問題:Python maya.parse方法的具體用法?Python maya.parse怎麽用?Python maya.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya
的用法示例。
在下文中一共展示了maya.parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: from_human
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def from_human(cls, string):
from_, to_ = string.split('-')
def parse_part(part):
part = part.replace('@', ' ')
parts = part.split()
weekday = parts[0]
time = parts[1]
timezone = parts[2] if len(parts) > 2 else 'UTC'
weekday = find_weekday(weekday)
time = maya.parse(time, timezone=timezone).datetime().time()
return weekday, time
from_weekday, from_time = parse_part(from_)
to_weekday, to_time = parse_part(to_)
return cls(from_weekday, from_time, to_weekday, to_time)
示例2: test_getting_datetime_for_local_timezone
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def test_getting_datetime_for_local_timezone(monkeypatch):
@property
def mock_local_tz(self):
class StaticTzInfo(object):
zone = "Europe/Zurich"
def __repr__(self):
return "<StaticTzInfo 'Europe/Zurich'>"
return StaticTzInfo()
monkeypatch.setattr(maya.MayaDT, "_local_tz", mock_local_tz)
d = maya.parse("1994-02-21T12:00:00+05:30")
dt = pytz.timezone("Europe/Zurich").localize(Datetime(1994, 2, 21, 7, 30))
assert d.local_datetime() == dt
示例3: date
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def date(spec):
return maya.parse(spec).datetime()
示例4: index
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def index(map_identifier, topic_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
image_occurrences = topic_store.get_topic_occurrences(
map_identifier, topic_identifier, "image", resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
images = []
for image_occurrence in image_occurrences:
images.append(
{
"identifier": image_occurrence.identifier,
"title": image_occurrence.get_attribute_by_name("title").value,
"scope": image_occurrence.scope,
"url": image_occurrence.resource_ref,
}
)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
return render_template(
"image/index.html", topic_map=topic_map, topic=topic, images=images, creation_date=creation_date,
)
示例5: index
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def index(map_identifier, topic_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
video_occurrences = topic_store.get_topic_occurrences(
map_identifier, topic_identifier, "video", resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
videos = []
for video_occurrence in video_occurrences:
videos.append(
{
"identifier": video_occurrence.identifier,
"title": video_occurrence.get_attribute_by_name("title").value,
"scope": video_occurrence.scope,
"url": video_occurrence.resource_ref,
}
)
# occurrences_stats = topic_store.get_topic_occurrences_statistics(map_identifier, topic_identifier)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
return render_template(
"video/index.html", topic_map=topic_map, topic=topic, videos=videos, creation_date=creation_date,
)
示例6: index
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def index(map_identifier, topic_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
link_occurrences = topic_store.get_topic_occurrences(
map_identifier, topic_identifier, "url", resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
links = []
for link_occurrence in link_occurrences:
links.append(
{
"identifier": link_occurrence.identifier,
"title": link_occurrence.get_attribute_by_name("title").value,
"scope": link_occurrence.scope,
"url": link_occurrence.resource_ref,
}
)
# occurrences_stats = topic_store.get_topic_occurrences_statistics(map_identifier, topic_identifier)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
return render_template(
"link/index.html", topic_map=topic_map, topic=topic, links=links, creation_date=creation_date,
)
示例7: network
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def network(map_identifier, topic_identifier):
topic_store = get_topic_store()
collaboration_mode = None
if current_user.is_authenticated: # User is logged in
is_map_owner = topic_store.is_topic_map_owner(map_identifier, current_user.id)
if is_map_owner:
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
else:
topic_map = topic_store.get_topic_map(map_identifier)
if topic_map is None:
abort(404)
collaboration_mode = topic_store.get_collaboration_mode(map_identifier, current_user.id)
# The map is private and doesn't belong to the user who is trying to
# access it
if not topic_map.published and not is_map_owner:
if not collaboration_mode: # The user is not collaborating on the map
abort(403)
else: # User is not logged in
topic_map = topic_store.get_topic_map(map_identifier)
if topic_map is None:
abort(404)
if not topic_map.published: # User is not logged in and the map is not published
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
return render_template(
"visualisation/network.html",
topic_map=topic_map,
topic=topic,
creation_date=creation_date,
collaboration_mode=collaboration_mode,
)
示例8: map
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def map(map_identifier, topic_identifier): # TODO: Shadows built-in name 'map'. Rename?
topic_store = get_topic_store()
collaboration_mode = None
if current_user.is_authenticated: # User is logged in
is_map_owner = topic_store.is_topic_map_owner(map_identifier, current_user.id)
if is_map_owner:
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
else:
topic_map = topic_store.get_topic_map(map_identifier)
if topic_map is None:
abort(404)
collaboration_mode = topic_store.get_collaboration_mode(map_identifier, current_user.id)
# The map is private and doesn't belong to the user who is trying to
# access it
if not topic_map.published and not is_map_owner:
if not collaboration_mode: # The user is not collaborating on the map
abort(403)
else: # User is not logged in
topic_map = topic_store.get_topic_map(map_identifier)
if topic_map is None:
abort(404)
if not topic_map.published: # User is not logged in and the map is not published
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
return render_template(
"visualisation/map.html",
topic_map=topic_map,
topic=topic,
creation_date=creation_date,
collaboration_mode=topic_map.collaboration_mode,
)
示例9: index
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def index(map_identifier, topic_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
file_occurrences = topic_store.get_topic_occurrences(
map_identifier, topic_identifier, "file", resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
files = []
for file_occurrence in file_occurrences:
files.append(
{
"identifier": file_occurrence.identifier,
"title": file_occurrence.get_attribute_by_name("title").value,
"scope": file_occurrence.scope,
"url": file_occurrence.resource_ref,
}
)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
return render_template(
"file/index.html", topic_map=topic_map, topic=topic, files=files, creation_date=creation_date,
)
示例10: index
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def index(map_identifier, topic_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
associations = topic_store.get_topic_associations(map_identifier, topic_identifier)
# occurrences_stats = topic_store.get_topic_occurrences_statistics(map_identifier, topic_identifier)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
return render_template(
"association/index.html",
topic_map=topic_map,
topic=topic,
associations=associations,
creation_date=creation_date,
)
示例11: index
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def index(map_identifier, topic_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
file_occurrences = topic_store.get_topic_occurrences(
map_identifier, topic_identifier, "3d-scene", resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
files = []
for file_occurrence in file_occurrences:
files.append(
{
"identifier": file_occurrence.identifier,
"title": file_occurrence.get_attribute_by_name("title").value,
"scope": file_occurrence.scope,
"url": file_occurrence.resource_ref,
}
)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
return render_template(
"three_d/index.html", topic_map=topic_map, topic=topic, files=files, creation_date=creation_date,
)
示例12: view_names
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def view_names(map_identifier, topic_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
current_app.logger.warning(
f"Topic map not found: user identifier: [{current_user.id}], topic map identifier: [{map_identifier}]"
)
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
current_app.logger.warning(
f"Topic not found: user identifier: [{current_user.id}], topic map identifier: [{map_identifier}], topic identifier: [{topic_identifier}]"
)
abort(404)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
return render_template("topic/view_names.html", topic_map=topic_map, topic=topic, creation_date=creation_date,)
示例13: get_logged_in_athlete_activities
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def get_logged_in_athlete_activities(self, after=0, list_activities=None):
"""List all activities after a given date
Parameters
----------
after: int, str or datetime object
If integer, the time since epoch is assumed
If str, the maya.parse() compatible date string is expected e.g. iso8601 or 2018-01-01 or 20180101
If datetime, the datetime object is expected
Returns
-------
list_activities: list
List of SummaryActivity objects
"""
if list_activities is None:
list_activities = []
after = date_to_epoch(after)
_fetched = self.activities_api.get_logged_in_athlete_activities(after=after)
if len(_fetched) > 0:
print(f"Fetched {len(_fetched)}, the latests is on {_fetched[-1].start_date}")
list_activities.extend(_fetched)
if len(_fetched) == 30:
last_after = list_activities[-1].start_date
return self.get_logged_in_athlete_activities(after=last_after, list_activities=list_activities)
else:
print("empty list")
return list_activities
示例14: _request_strava_authorize
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def _request_strava_authorize(client_id, port):
params_oauth = {
"client_id": client_id,
"response_type": "code",
"redirect_uri": f"http://localhost:{port}/authorization_successful",
"scope": "read,profile:read_all,activity:read",
"state": 'https://github.com/sladkovm/strava-http',
"approval_prompt": "force"
}
values_url = urllib.parse.urlencode(params_oauth)
base_url = 'https://www.strava.com/oauth/authorize'
rv = base_url + '?' + values_url
webbrowser.get().open(rv)
return None
示例15: run_server_and_wait_for_token
# 需要導入模塊: import maya [as 別名]
# 或者: from maya import parse [as 別名]
def run_server_and_wait_for_token(port, client_id, client_secret):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('127.0.0.1', port))
s.listen()
conn, addr = s.accept()
request_bytes = b''
with conn:
while True:
chunk = conn.recv(512)
request_bytes += chunk
if request_bytes.endswith(b'\r\n\r\n'):
break
conn.sendall(b'HTTP/1.1 200 OK\r\n\r\nsuccess\r\n')
request = request_bytes.decode('utf-8')
status_line = request.split('\n', 1)[0]
method, raw_url, protocol_version = status_line.split(' ')
url = urllib.parse.urlparse(raw_url)
query_string = url.query
query_params = urllib.parse.parse_qs(query_string, keep_blank_values=True)
if url.path == "/authorization_successful":
code = query_params.get('code')[0]
logger.debug(f"code: {code}")
params = {
"client_id": client_id,
"client_secret": client_secret,
"code": code,
"grant_type": "authorization_code"
}
r = requests.post("https://www.strava.com/oauth/token", params)
data = r.json()
logger.debug(f"Authorized athlete: {data.get('access_token', 'Oeps something went wrong!')}")
else:
data = url.path.encode()
return data