Пример #1
0
    def create_entities(cls, request, response):
        logger = logging.getLogger('project')
        try:
            input_data = [request.Value]
            try:
                input_data_json = {"places": input_data}

                url = template_url.format(host=host, port=port)
                resource = send_post(url, json=input_data_json)
            except Exception as e:
                response.addUIMessage("Error: " + str(e), UIM_TYPES["partial"])
            else:
                if resource.status_code == 200:
                    output_data = resource.json()
                    if output_data['status']:
                        for block in output_data['result']:
                            for line in block["rows"]:
                                logger.info(line)
                                lat, lon = round(line['lat'], 5), round(line['lon'], 5)
                                _record_str = f"{lat},{lon}"
                                en = response.addEntity(GPS, _record_str)
                                en.addProperty(displayName="latitude", fieldName="latitude", value=lat)
                                en.addProperty(displayName="longitude", fieldName="longitude", value=lon)
                                if 'link_to_image' in line:
                                    if len(line['link_to_image']) > 0:
                                        en = response.addEntity(Image, line['name_address'])
                                        en.addProperty(displayName="description", fieldName="description", value=line['name_address'])
                                        en.addProperty(displayName="url", fieldName="url", value=line['link_to_image'])
                                if 'link_to_plus_codes' in line:
                                    if len(line['link_to_plus_codes']) > 0:
                                        link_to_codes = line['link_to_plus_codes']
                                        en = response.addEntity(URL, link_to_codes)
                                        en.setLinkLabel('Google plus codes')
                                        en.addProperty(displayName="url", fieldName="url", value=line['link_to_plus_codes'])
                                        en.addProperty(displayName="title", fieldName="title",
                                                       value="Location with Google plus codes")
                                        _google_address = str(line["formatted_address"]).encode('utf-8')
                                        # sorry, dev with Windows 10 with local RU
                                        google_address = _google_address.decode('cp1251')
                                        en.addDisplayInformation(f'<a href="{line["link_to_plus_codes"]}">{google_address}</a>', "Map with Google")

        except Exception as e:
            response.addUIMessage("Error: " + str(e), UIM_TYPES["partial"])
Пример #2
0
def send_reset_email(user):
    MAILGUN_DOMAIN = os.environ['MAILGUN_DOMAIN']
    MAILGUN_API_KEY = os.environ['MAILGUN_API_KEY']
    FROM_TITLE = 'Reset Password'
    FROM_EMAIL = os.environ['MAILGUN_EMAIL']
    token = user.get_reset_token()
    response = send_post(
        f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
        auth=("api", MAILGUN_API_KEY),
        data={
            'from': f"{FROM_TITLE} <{FROM_EMAIL}>",
            'to': user.email,
            'subject': 'RESET YOUR PASSWORD',
            'text': f'''To reset your password, visit the following link:
{url_for('users.reset_token', token=token, _external=True)}

If you did not make this request then simply ignore this email and no changes will be made.
''',
            'html': ''
        })
Пример #3
0
def send_generated_login(user, gen_password):
    MAILGUN_DOMAIN = os.environ['MAILGUN_DOMAIN']
    MAILGUN_API_KEY = os.environ['MAILGUN_API_KEY']
    FROM_TITLE = 'Login Password for Treasure Hunt (Nakshatra\' 20)'
    FROM_EMAIL = os.environ['MAILGUN_EMAIL']
    response = send_post(
        f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN}/messages",
        auth=("api", MAILGUN_API_KEY),
        data={
            'from': f"{FROM_TITLE} <{FROM_EMAIL}>",
            'to': user.email,
            'subject':
            f'Login Password for Treasure Hunt (Nakshatra\' 20): {gen_password}',
            'text': f'''Your details:
username: {user.email}
password: {gen_password}
If you did not make this request then simply ignore this email and no changes will be made.
''',
            'html': ''
        })
Пример #4
0
 def get_token(self, request):
     """从第三方服务提供方获得 token"""
     code = request.GET.get("code")
     redirect = b64decode(request.GET.get('redirect')).decode('utf-8')
     # TODO: consume the state, if not present, don't proceed
     state = request.GET.get("state")
     post_data = {
         "client_id": self.client_id,
         "client_secret": self.client_secret,
         "redirect_uri": redirect,
         "state": state,
         "code": code,
     }
     data = send_post(f"{self.token_host['github']}",
                      json=post_data,
                      headers={
                          "accept": "application/json"
                      }).json()
     self.access_token = data.get("access_token")
     self.token_type = data.get("token_type")
     self.error = data.get("error")
     pass