⠛⠥⠝⠑⠽⠎⠥⠎ /home/asguneysu

Redirect Mobile Devices to App Stores

by Ahmed Şeref Güneysu

<details class="ba bw2 mv2 pa2 b--light-gray">
    <summary class="fira mv1 dim fw7">Application</summary>
    <span><a download="app.py" class="link black bg-animate hover-bg-light-yellow pv3 ph3" href="./src/app.py"><i
        class="icon icon-download"> </i> download</a> </span>        
    <div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="ch">#!/usr/bin/env python</span>

# coding:utf-8 from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop from tornado.options import options, define, parse_command_line from tornado.web import RequestHandler, Application, url from user_agents import parse

define(name="port", default=8000, help="Port")

STORE_URLS = { "iPhone": "https://itunes.apple.com/us/app/jokermenu/id1086543332?l=tr&ls=1&mt=8", "Android": "https://play.google.com/store/apps/details?id=com.menu.joker", }

# noinspection PyAbstractClass class HomeHandler(RequestHandler): def get(self): ua_string = self.request.headers.get('user-agent', '') os_family = self.get_os(ua_string)

    <span class="k">if</span> <span class="n">os_family</span> <span class="o">==</span> <span class="s2">&#34;Android&#34;</span><span class="p">:</span>
        <span class="c1"># even on firefox it works, this does not work on chrome on android</span>
        <span class="c1"># see:</span>
        <span class="c1"># - https://bugs.chromium.org/p/chromium/issues/detail?id=454396</span>
        <span class="c1"># - http://stackoverflow.com/a/28279849/1766716</span>
        <span class="c1"># self.redirect(url=&#34;market://details?id=com.menu.joker&#34;, permanent=False)</span>

        <span class="c1"># intent name (install) and scheme (get) can be arbitrary strings.</span>
        <span class="c1"># only package parameter required</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redirect</span><span class="p">(</span><span class="s2">&#34;intent://install#Intent;scheme=get;package=com.menu.joker;end&#34;</span><span class="p">)</span>

    <span class="k">elif</span> <span class="n">os_family</span> <span class="o">==</span> <span class="s2">&#34;iPhone&#34;</span><span class="p">:</span>
        <span class="c1"># self.redirect(url=STORE_URLS[&#34;iPhone&#34;], permanent=False)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redirect</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="s2">&#34;itms://itunes.apple.com/us/app/apple-store/id1086543332?l=tr&amp;ls=1&amp;mt=8&#34;</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">redirect</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="s2">&#34;https://joker.menu&#34;</span><span class="p">,</span> <span class="n">permanent</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>

<span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">get_os</span><span class="p">(</span><span class="n">ua_string</span><span class="p">):</span>
    <span class="n">user_agent</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="n">ua_string</span><span class="p">)</span>
    <span class="n">os_family</span> <span class="o">=</span> <span class="n">user_agent</span><span class="o">.</span><span class="n">os</span><span class="o">.</span><span class="n">family</span>
    <span class="k">return</span> <span class="n">os_family</span>

urls = [ url(pattern=r'/', handler=HomeHandler, name="home"), ]

application = Application(handlers=urls)

def main(): server = HTTPServer(application) parse_command_line() server.listen(port=options.port, address="0.0.0.0") server.start(num_processes=1) IOLoop.instance().start()

if __name__ == 'main': main()

<details class="ba bw2 mv2 pa2 b--light-gray">
    <summary class="fira mv1 dim fw7">Requirements</summary>
    <span><a download="requirements.txt" class="link black bg-animate hover-bg-light-yellow pv3 ph3" href="./src/requirements.txt"><i
        class="icon icon-download"> </i> download</a> </span>        
    <div class="highlight"><pre class="chroma"><code class="language-txt" data-lang="txt">tornado==4.5.1

user-agents==1.1.0

DMCA.com Protection Status