コード例 #1
0
    def handle(self, *args, **options):
        cur = connection.cursor()
        g = GeoIP()
        cur.execute(
            "SELECT id, release_id, created, ip4addr FROM apps_download")
        for id, release_id, created, ip4addr in cur.fetchall():
            release = Release.objects.get(id=release_id)
            app = release.app
            when = created.date()

            a_str = '{0:5} {1:30} {2:15} {3:10} {4:15}'.format(
                id, app.fullname, release.version, str(when),
                ipaddr_long_to_str(ip4addr))
            sys.stdout.write(a_str + '\n')
            sys.stdout.flush()

            dl = Download.objects.create(release=release,
                                         when=when,
                                         ip4addr=ip4addr)
            dl.save()

            increment_count(ReleaseDownloadsByDate, release=release, when=when)
            increment_count(ReleaseDownloadsByDate, release=None, when=when)

            geoinfo = g.city(ipaddr_long_to_str(ip4addr))
            if geoinfo:
                country_geoloc, _ = GeoLoc.objects.get_or_create(
                    country=geoinfo['country_code'], region='', city='')
                increment_count(AppDownloadsByGeoLoc,
                                app=app,
                                geoloc=country_geoloc)
                increment_count(AppDownloadsByGeoLoc,
                                app=None,
                                geoloc=country_geoloc)

                if geoinfo.get('city'):
                    city_geoloc, _ = GeoLoc.objects.get_or_create(
                        country=geoinfo['country_code'],
                        region=geoinfo['region'],
                        city=geoinfo['city'])
                    increment_count(AppDownloadsByGeoLoc,
                                    app=app,
                                    geoloc=city_geoloc)
                    increment_count(AppDownloadsByGeoLoc,
                                    app=None,
                                    geoloc=city_geoloc)

            sys.stdout.write('\n')
コード例 #2
0
ファイル: views.py プロジェクト: cytoscape/appstore
def release_download(request, app_name, version):
    release = get_object_or_404(Release, app__name = app_name, version = version, active = True)
    ip4addr = _client_ipaddr(request)
    when    = datetime.date.today()

    # Update the App object
    release.app.downloads += 1
    release.app.save()

    # Record the download as a Download object
    Download.objects.create(release = release, ip4addr = ip4addr, when = when)

    # Record the download in the timeline
    _increment_count(ReleaseDownloadsByDate, release = release, when = when)
    _increment_count(ReleaseDownloadsByDate, release = None,    when = when)

    # Look up geographical information about the user's IP address
    geoinfo = geoIP.city(ipaddr_long_to_str(ip4addr))
    if geoinfo:
        # Record the download in the user's country
        country_geoloc, _ = GeoLoc.objects.get_or_create(country = geoinfo['country_code'], region = '', city = '')
        _increment_count(AppDownloadsByGeoLoc, app = release.app, geoloc = country_geoloc)
        _increment_count(AppDownloadsByGeoLoc, app = None,        geoloc = country_geoloc)

        if geoinfo.get('city'):
            # Record the download in the user's city
            city_geoloc, _ = GeoLoc.objects.get_or_create(country = geoinfo['country_code'], region = geoinfo['region'], city = geoinfo['city'])
            _increment_count(AppDownloadsByGeoLoc, app = release.app,  geoloc = city_geoloc)
            _increment_count(AppDownloadsByGeoLoc, app = None,         geoloc = city_geoloc)

    return HttpResponseRedirect(release.release_file_url)
コード例 #3
0
    def handle(self, *args, **options):
        cur = connection.cursor()
        g = GeoIP()
        cur.execute("SELECT id, release_id, created, ip4addr FROM apps_download")
        for id, release_id, created, ip4addr in cur.fetchall():
            release = Release.objects.get(id = release_id)
            app     = release.app
            when    = created.date()

            print '{0:5} {1:30} {2:15} {3:10} {4:15}'.format(id, app.fullname, release.version, str(when), ipaddr_long_to_str(ip4addr)),
            sys.stdout.flush()

            dl = Download.objects.create(release = release, when = when, ip4addr = ip4addr)
            dl.save()

            increment_count(ReleaseDownloadsByDate, release = release, when = when)
            increment_count(ReleaseDownloadsByDate, release = None,    when = when)

            geoinfo = g.city(ipaddr_long_to_str(ip4addr))
            if geoinfo:
                country_geoloc, _ = GeoLoc.objects.get_or_create(country = geoinfo['country_code'], region = '', city = '')
                increment_count(AppDownloadsByGeoLoc, app = app,  geoloc = country_geoloc)
                increment_count(AppDownloadsByGeoLoc, app = None, geoloc = country_geoloc)

                if geoinfo.get('city'):
                    city_geoloc, _ = GeoLoc.objects.get_or_create(country = geoinfo['country_code'], region = geoinfo['region'], city = geoinfo['city'])
                    increment_count(AppDownloadsByGeoLoc, app = app,  geoloc = city_geoloc)
                    increment_count(AppDownloadsByGeoLoc, app = None, geoloc = city_geoloc)
                    
            print
コード例 #4
0
ファイル: views.py プロジェクト: sarthak-srivastava/appstore
def release_download(request, app_name, version):
    release = get_object_or_404(Release,
                                app__name=app_name,
                                version=version,
                                active=True)
    ip4addr = _client_ipaddr(request)
    when = datetime.date.today()

    # Update the App object
    release.app.downloads += 1
    release.app.save()

    # Record the download as a Download object
    Download.objects.create(release=release, ip4addr=ip4addr, when=when)

    # Record the download in the timeline
    _increment_count(ReleaseDownloadsByDate, release=release, when=when)
    _increment_count(ReleaseDownloadsByDate, release=None, when=when)

    # Look up geographical information about the user's IP address
    geoinfo = geoIP.city(ipaddr_long_to_str(ip4addr))
    if geoinfo:
        # Record the download in the user's country
        country_geoloc, _ = GeoLoc.objects.get_or_create(
            country=geoinfo['country_code'], region='', city='')
        _increment_count(AppDownloadsByGeoLoc,
                         app=release.app,
                         geoloc=country_geoloc)
        _increment_count(AppDownloadsByGeoLoc, app=None, geoloc=country_geoloc)

        if geoinfo.get('city'):
            # Record the download in the user's city
            city_geoloc, _ = GeoLoc.objects.get_or_create(
                country=geoinfo['country_code'],
                region=geoinfo['region'],
                city=geoinfo['city'])
            _increment_count(AppDownloadsByGeoLoc,
                             app=release.app,
                             geoloc=city_geoloc)
            _increment_count(AppDownloadsByGeoLoc,
                             app=None,
                             geoloc=city_geoloc)

    return HttpResponseRedirect(release.release_file_url)
コード例 #5
0
ファイル: models.py プロジェクト: sarthak-srivastava/appstore
 def __unicode__(self):
     return unicode(self.release) + u' ' + unicode(self.when) + u' ' + ipaddr_long_to_str(self.ip4addr)