Exemple #1
0
def runtests(dataFile):
    if (os.path.isfile(dataFile)):
        start = time.time()
        provider = fiftyone_degrees_mobile_detector_v3_trie_wrapper.Provider(
            dataFile, properties)

        end = time.time()

        print "   Initialization time: %s ms" % ((end - start) * 1000)
        print "   Time per detection: %s ms" % speedtest(provider)
        print "   Memory usage: %d Mb" % (
            resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1000)
        del (provider)
    else:
        print "   %s could not be found." % dataFile
Exemple #2
0
 def __init__(self):
     if settings.V3_TRIE_WRAPPER_DATABASE:
         try:
             # Does the database file exists and is it readable?
             with open(settings.V3_TRIE_WRAPPER_DATABASE):
                 pass
         except IOError:
             raise Exception(
                 'The provided detection database file (%s) does not '
                 'exist or is not readable. Please, '
                 'check your settings.' % settings.V3_TRIE_WRAPPER_DATABASE)
         else:
             from FiftyOneDegrees import fiftyone_degrees_mobile_detector_v3_trie_wrapper
             self.provider = fiftyone_degrees_mobile_detector_v3_trie_wrapper.Provider(settings.V3_TRIE_WRAPPER_DATABASE, settings.PROPERTIES)
     else:
         raise Exception(
             'Trie-based detection method depends on an external '
             'database file. Please, check your settings.')
</pre></p>
</ol>
This example can be run in any directory, but assumes your
settings file contains a valid dataFile location and has the
IsMobile property selected.
</tutorial>
'''
# // Snippet Start
from FiftyOneDegrees import fiftyone_degrees_mobile_detector_v3_trie_wrapper
from fiftyone_degrees.mobile_detector.conf import settings
import sys

dataFile = settings.V3_TRIE_WRAPPER_DATABASE
properties = settings.PROPERTIES

provider = fiftyone_degrees_mobile_detector_v3_trie_wrapper.Provider(
    dataFile, properties)

# User-Agent string of an iPhone mobile device.
mobileUserAgent = (
    "Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) "
    "AppleWebKit/537.51.2 (KHTML, like Gecko) 'Version/7.0 Mobile/11D167 "
    "Safari/9537.53")

# User-Agent string of Firefox Web browser version 41 on desktop.
desktopUserAgent = ("Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) "
                    "Gecko/20100101 Firefox/41.0")

# User-Agent string of a MediaHub device.
mediaHubUserAgent = (
    "Mozilla/5.0 (Linux; Android 4.4.2; X7 Quad Core "
    "Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 "