当前位置: 首页>>代码示例>>Python>>正文


Python Config.get_mongo_url方法代码示例

本文整理汇总了Python中config.config.Config.get_mongo_url方法的典型用法代码示例。如果您正苦于以下问题:Python Config.get_mongo_url方法的具体用法?Python Config.get_mongo_url怎么用?Python Config.get_mongo_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在config.config.Config的用法示例。


在下文中一共展示了Config.get_mongo_url方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_tournament

# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_mongo_url [as 别名]
def import_tournament(type, path, bracket, region, name):
    config = Config()
    mongo_client = MongoClient(host=config.get_mongo_url())

    if type == 'tio':
        scraper = TioScraper(path, bracket)
    elif type =='challonge':
        scraper = ChallongeScraper(path)
    else:
        click.echo("Illegal type")

    dao = Dao(region, mongo_client=mongo_client)

    player_map = get_player_alias_to_id_map(scraper, dao)

    # TODO pass in a map of overrides for specific players
    tournament = Tournament.from_scraper(type, scraper, player_map, region)
    if name:
        tournament.name = name

    dao.insert_tournament(tournament)

    click.echo("Generating new ranking...")
    rankings.generate_ranking(dao)

    click.echo("Done!")
开发者ID:AJAnderson,项目名称:garpr,代码行数:28,代码来源:import_tournament.py

示例2: TestConfig

# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_mongo_url [as 别名]
class TestConfig(unittest.TestCase):
    def setUp(self):
        self.config = Config(TEMPLATE_CONFIG_FILE)

    def test_get_mongo_url(self):
        self.assertEquals(self.config.get_mongo_url(), 'mongodb://USER:[email protected]/AUTH_DB')

    def test_get_db_host(self):
        self.assertEquals(self.config.get_db_host(), 'HOSTNAME')

    def test_get_auth_db_name(self):
        self.assertEquals(self.config.get_auth_db_name(), 'AUTH_DB')

    def test_get_db_user(self):
        self.assertEquals(self.config.get_db_user(), 'USER')

    def test_get_db_password(self):
        self.assertEquals(self.config.get_db_password(), 'PASSWORD')

    def test_challonge_api_key(self):
        self.assertEquals(self.config.get_challonge_api_key(), 'API_KEY')

    def test_get_fb_app_id(self):
        self.assertEquals(self.config.get_fb_app_id(), 'FB_APP_ID')

    def test_get_fb_app_token(self):
        self.assertEquals(self.config.get_fb_app_token(), 'FB_APP_TOKEN')
开发者ID:AJAnderson,项目名称:garpr,代码行数:29,代码来源:test_config.py

示例3: len

# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_mongo_url [as 别名]
import os
import sys

from pymongo import MongoClient

# add root directory to python path
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '/../'))

from config.config import Config
from dao import Dao

# script to create new user in db
if __name__ == "__main__":
    if len(sys.argv) < 4:
        print "incorrect number of arguments!"
        print "usage: python create_user.py username password region1 [region2] [region3]...."
        sys.exit()

    username = sys.argv[1]
    password = sys.argv[2]
    regions =  sys.argv[3:]

    config = Config()
    mongo_client = MongoClient(host=config.get_mongo_url())
    dao = Dao(None, mongo_client)
    if dao.create_user(username, password, regions):
        print "user created:", username
开发者ID:BrandonCookeDev,项目名称:garpr,代码行数:29,代码来源:create_user.py

示例4: validate

# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_mongo_url [as 别名]
def validate(fix=False):
    config = Config()
    mongo_client = MongoClient(host=config.get_mongo_url())
    database_name = config.get_db_name()

    # db collections
    players_col = mongo_client[database_name][M.Player.collection_name]
    tournaments_col = mongo_client[database_name][M.Tournament.collection_name]
    rankings_col = mongo_client[database_name][M.Ranking.collection_name]
    users_col = mongo_client[database_name][M.User.collection_name]
    pending_tournaments_col = mongo_client[database_name][M.PendingTournament.collection_name]
    merges_col = mongo_client[database_name][M.Merge.collection_name]
    sessions_col = mongo_client[database_name][M.Session.collection_name]
    raw_files_col = mongo_client[database_name][M.RawFile.collection_name]
    regions_col = mongo_client[database_name][M.Region.collection_name]

    # get sets of ids for cross-referencing
    player_ids = set([p.get('_id') for p in players_col.find()])
    tournament_ids = set([t.get('_id') for t in tournaments_col.find()])
    ranking_ids = set([r.get('_id') for r in rankings_col.find()])
    user_ids = set([u.get('_id') for u in users_col.find()])
    pending_tournament_ids = set([pt.get('_id') for pt in pending_tournaments_col.find()])
    merge_ids = set([m.get('_id') for m in merges_col.find()])
    raw_file_ids = set([rf.get('_id')
        for rf in raw_files_col.find({}, {'data': 0})])
    region_ids = set([r.get('_id') for r in regions_col.find()])

    # Player checks
    for p in players_col.find():
        player = M.Player.load(p, context='db')
        error_header = '[ERROR player "{}" ({})]'.format(player.id, player.name)
        modified = False

        # check: player valid
        valid, validate_errors = player.validate()
        if not valid:
            print error_header, validate_errors

        # check: player regions are all valid regions
        for r in player.regions:
            if r not in region_ids:
                print error_header, 'invalid region {}'.format(r)
        if fix:
            # fix: remove invalid regions from player regions
            if any([r not in region_ids for r in player.regions]):
                modified = True
                player.regions = [r for r in player.regions if r in region_ids]


        # check: ratings all have valid regions
        for r in player.ratings.keys():
            if r not in region_ids:
                print error_header, 'invalid rating region {}'.format(r)
                if fix:
                    # fix: remove rating from player
                    del player.ratings[r]
                    modified = True

        # check: merge_parent is real player if exists
        if player.merge_parent is not None:
            if player.merge_parent not in player_ids:
                print error_header, 'invalid merge_parent {}'.format(player.merge_parent)
                if fix:
                    # fix: set merge_parent to None, unset merged
                    player.merge_parent = None
                    player.merged = False

        # check: merge_children are real players
        for mc in player.merge_children:
            if mc not in player_ids:
                print error_header, 'invalid merge_child {}'.format(mc)
        if fix:
            # fix: remove child from merge_children
            if any([mc not in player_ids for mc in player.merge_children]):
                modified = True
                player.merge_children = [mc for mc in player.merge_children if mc in player_ids]

        if fix and modified:
            print error_header, 'fixing player..'
            players_col.update({'_id': player.id}, player.dump(context='db'))


    # Tournament checks
    for t in tournaments_col.find():
        tournament = M.Tournament.load(t, context='db')
        error_header = '[ERROR tournament "{}" ({})]'.format(tournament.id, tournament.name)
        modified = False

        # check: tournament valid
        valid, validate_errors = tournament.validate()
        if not valid:
            print error_header, validate_errors
            if fix:
                # fix: set players equal to set of players in matches
                modified = True
                tournament.players = list({match.winner for match in tournament.matches} | \
                              {match.loser for match in tournament.matches})
                tournament.orig_ids = list(tournament.players)

        # check: tournament empty
#.........这里部分代码省略.........
开发者ID:garsh0p,项目名称:garpr,代码行数:103,代码来源:validate_db.py

示例5: Config

# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_mongo_url [as 别名]
from datetime import datetime
from model import MatchResult, Tournament, PendingTournament, Merge, User, Player
import re
from scraper.tio import TioScraper
from scraper.challonge import ChallongeScraper
import alias_service
from StringIO import StringIO
import Cookie
from Cookie import CookieError

TYPEAHEAD_PLAYER_LIMIT = 20

# parse config file
config = Config()

mongo_client = MongoClient(host=config.get_mongo_url())
print "parsed config: ", config.get_mongo_url()

app = Flask(__name__)
# cors = CORS(app, origins='whensgarpr.com') #im not 100% sure on all this
cors = CORS(app, origins='localhost', headers=['Authorization', 'Content-Type'])
api = restful.Api(app)

player_list_get_parser = reqparse.RequestParser()
player_list_get_parser.add_argument('alias', type=str)
player_list_get_parser.add_argument('query', type=str)

tournament_list_get_parser = reqparse.RequestParser()
tournament_list_get_parser.add_argument('includePending', type=str)

matches_get_parser = reqparse.RequestParser()
开发者ID:acoulon99,项目名称:garpr,代码行数:33,代码来源:server.py

示例6: Config

# 需要导入模块: from config.config import Config [as 别名]
# 或者: from config.config.Config import get_mongo_url [as 别名]
from dao import Dao
from pymongo import MongoClient
import rankings
from config.config import Config

config = Config()
mongo_client = MongoClient(config.get_mongo_url())
regions = Dao.get_all_regions(mongo_client)
for region in regions:
    d = Dao(region.id, mongo_client)
    rankings.generate_ranking(d)
开发者ID:AJAnderson,项目名称:garpr,代码行数:13,代码来源:generate_rankings.py


注:本文中的config.config.Config.get_mongo_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。