def __init__(self, parent=None): """Constructor.""" self.connection = None self.comboBoxDBIdx = -10 self.comboBoxCollectionIdx = -10 self.mongoUtil = MongoUtil() super(MongQGISDialog, self).__init__(parent) # Set up the user interface from Designer. # After setupUI you can access any designer object by doing # self.<objectname>, and you can use autoconnect slots - see # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html # #widgets-and-dialogs-with-auto-connect self.setupUi(self)
def __init__(self): self.mongo_cli = MongoUtil(MONGO_INFO['host'], MONGO_INFO['db'], MONGO_INFO['collection']) self.post_api = 'http://10.111.0.154:9100/post/import' self.transform_video_api = 'http://10.111.0.154:10100/video/add?uid=12299265&video_id=%s&media_id=%s&pic_url=%s'
class ArticlePoster(object): def __init__(self): self.mongo_cli = MongoUtil(MONGO_INFO['host'], MONGO_INFO['db'], MONGO_INFO['collection']) self.post_api = 'http://10.111.0.154:9100/post/import' self.transform_video_api = 'http://10.111.0.154:10100/video/add?uid=12299265&video_id=%s&media_id=%s&pic_url=%s' def __load_items(self, query): q = { 't_p' : {'$exists' : False} } q.update(query) for item in self.mongo_cli.find_all(q, 10): yield item def get_blind_url(self, video_id, media_id, poster_url): resp = fetch_html(self.transform_video_api % (video_id, media_id, urllib.quote(poster_url))) try: data = json.loads(resp) except Exception: return result = data.get('result') return result.get('url'), result.get('cover_pic') def post_article(self, media_name, media_id, query): for item in self.__load_items(query): video_id = item.get('ks3_key') poster_url = item.get('poster') # get compressed video stream url and poster url video_url, poster_url = self.get_blind_url(video_id, media_id, poster_url) # format article content desc = ensure_utf8(item.get('content')) content = self.gen_content(video_url, poster_url, desc) self.publish_article( item.get('web_url'), media_name, media_id, ensure_utf8(item.get('title')), content, video_id ) item['t_p'] = int(time.time()) self.mongo_cli.save(item) print 'name: %s, title : %s' % (ensure_utf8(media_name), ensure_utf8(item.get('title'))) def gen_content(self, video_url, poster_url, desc): src = ''' javascript:void(function(a) {{ document.open(undefined); if((typeof android !== 'undefined') && navigator.userAgent.toLowerCase(undefined).indexOf('android') > -1) {{ document.write('<div style=\\'width:100%;height:100%;background-image:url({poster_url});background-size:100%;text-align:center;\\' onclick=\\'window.top.android.playVideo(this.dataset.vid)\\' data-vid=\\'{video_url}\\' > <img style=\\'width:100px;position:relative;top:50%;margin-top:-50px;\\' src=\\'http://staticimg.yidianzixun.com/s/wemedia/201511/AroEyewGT.png \\' /> </div>'); return; }} document.write('<video src=\\'{video_url}\\' style=\\'width:100%;height:100%;\\' poster=\\'{poster_url}\\' controls preload=\\'none\\'></video>'); document.close(undefined); }}(1)) '''.format(video_url=video_url, poster_url=poster_url) return ''' <iframe id="yidian_frame_d2c5f9f70" width="100%" height="380px" frameborder="0" onload="this.style.height=(this.clientWidth||window.innerWidth)/16*9+'px';this.style.display='block'" style="display:block;" scrolling="no" src="{video_src}"> </iframe> <p>{desc}<p> '''.format(video_src=src, desc=desc) def publish_article(self, url, media_name, media_id, title, content, video_id): data = { 'media_name' : media_name, 'media_id' : media_id, 'title' : title, 'content' : content, 'import_hash' : hash_str(url), 'date' : str_to_mcroseconds('2015-10-21 18:50:00'), 'import_url' : url, 'passed' : '1', 'video_id' : video_id } headers = { 'Content-Type' : 'application/json' } resp = fetch_html(self.post_api, headers=headers, body=json.dumps(data)) print resp
class ArticlePoster(object): def __init__(self): self.mongo_cli = MongoUtil(MONGO_INFO['host'], MONGO_INFO['db'], MONGO_INFO['collection']) self.post_api = 'http://10.111.0.154:9100/post/import' self.transform_video_api = 'http://10.111.0.154:10100/video/add?uid=12299265&video_id=%s&media_id=%s&pic_url=%s' def __load_items(self, query): q = {'t_p': {'$exists': False}} q.update(query) for item in self.mongo_cli.find_all(q, 10): yield item def get_blind_url(self, video_id, media_id, poster_url): resp = fetch_html(self.transform_video_api % (video_id, media_id, urllib.quote(poster_url))) try: data = json.loads(resp) except Exception: return result = data.get('result') return result.get('url'), result.get('cover_pic') def post_article(self, media_name, media_id, query): for item in self.__load_items(query): video_id = item.get('ks3_key') poster_url = item.get('poster') # get compressed video stream url and poster url video_url, poster_url = self.get_blind_url(video_id, media_id, poster_url) # format article content desc = ensure_utf8(item.get('content')) content = self.gen_content(video_url, poster_url, desc) self.publish_article(item.get('web_url'), media_name, media_id, ensure_utf8(item.get('title')), content, video_id) item['t_p'] = int(time.time()) self.mongo_cli.save(item) print 'name: %s, title : %s' % (ensure_utf8(media_name), ensure_utf8(item.get('title'))) def gen_content(self, video_url, poster_url, desc): src = ''' javascript:void(function(a) {{ document.open(undefined); if((typeof android !== 'undefined') && navigator.userAgent.toLowerCase(undefined).indexOf('android') > -1) {{ document.write('<div style=\\'width:100%;height:100%;background-image:url({poster_url});background-size:100%;text-align:center;\\' onclick=\\'window.top.android.playVideo(this.dataset.vid)\\' data-vid=\\'{video_url}\\' > <img style=\\'width:100px;position:relative;top:50%;margin-top:-50px;\\' src=\\'http://staticimg.yidianzixun.com/s/wemedia/201511/AroEyewGT.png \\' /> </div>'); return; }} document.write('<video src=\\'{video_url}\\' style=\\'width:100%;height:100%;\\' poster=\\'{poster_url}\\' controls preload=\\'none\\'></video>'); document.close(undefined); }}(1)) '''.format(video_url=video_url, poster_url=poster_url) return ''' <iframe id="yidian_frame_d2c5f9f70" width="100%" height="380px" frameborder="0" onload="this.style.height=(this.clientWidth||window.innerWidth)/16*9+'px';this.style.display='block'" style="display:block;" scrolling="no" src="{video_src}"> </iframe> <p>{desc}<p> '''.format(video_src=src, desc=desc) def publish_article(self, url, media_name, media_id, title, content, video_id): data = { 'media_name': media_name, 'media_id': media_id, 'title': title, 'content': content, 'import_hash': hash_str(url), 'date': str_to_mcroseconds('2015-10-21 18:50:00'), 'import_url': url, 'passed': '1', 'video_id': video_id } headers = {'Content-Type': 'application/json'} resp = fetch_html(self.post_api, headers=headers, body=json.dumps(data)) print resp
class MongQGISDialog(QtGui.QDialog, FORM_CLASS): db = None collection = None x = None y = None def __init__(self, parent=None): """Constructor.""" self.connection = None self.comboBoxDBIdx = -10 self.comboBoxCollectionIdx = -10 self.mongoUtil = MongoUtil() super(MongQGISDialog, self).__init__(parent) # Set up the user interface from Designer. # After setupUI you can access any designer object by doing # self.<objectname>, and you can use autoconnect slots - see # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html # #widgets-and-dialogs-with-auto-connect self.setupUi(self) def on_btnConnect_released(self): try: _host = str(self.host.displayText()) _port = int(self.port.displayText()) self.setStatusText('Connecting to %s:%d...' % (_host, _port)) from pymongo import MongoClient self.connection = MongoClient(_host, _port) self.comboBoxDBs.clear() self.comboBoxDBs.setEnabled(True) self.comboBoxDBs.addItem('<select a database>') self.setStatusText('Fetching database names...') dbs = self.connection.database_names() for db in dbs: self.comboBoxDBs.addItem(db) self.setStatusText('Please select a database...') #self.comboBoxColls.addItem('<select collection>') #self.labelLongitudeField.setEnabled(False) #self.comboBoxLongField.setEnabled(False) #self.comboBoxDBs.clear() except: self.setStatusText('Connection failure.') def on_comboBoxDBs_currentIndexChanged(self): if self.comboBoxDBs.currentIndex() == 0: self.comboBoxCollections.setEnabled(False) return if str(self.comboBoxDBs.itemText(self.comboBoxDBs.currentIndex())) == '': return if str(self.comboBoxDBs.itemText(self.comboBoxDBs.currentIndex())) == '<select a database>': return if self.comboBoxDBIdx == self.comboBoxDBs.currentIndex(): return self.comboBoxDBIdx = self.comboBoxDBs.currentIndex() self.setStatusText('Fetching collection names...') self.comboBoxCollections.clear() self.comboBoxCollections.addItem('<select a collection>') self.db = str(self.comboBoxDBs.itemText(self.comboBoxDBs.currentIndex())) _colls = self.mongoUtil.getGeoCollectionNames(self.connection[self.db]) for coll in _colls: self.comboBoxCollections.addItem(coll) self.comboBoxCollections.setEnabled(True) #self.labelLongitudeField.setEnabled(False) #self.comboBoxLongField.setEnabled(False) self.setStatusText('Please select a collection...') def on_comboBoxCollections_currentIndexChanged(self): if self.comboBoxCollectionIdx == self.comboBoxCollections.currentIndex(): return #self.labelLongitudeField.setEnabled(False) #self.comboBoxLongField.setEnabled(False) self.comboBoxCollectionIdx = self.comboBoxCollections.currentIndex() #self.btnOk.setEnabled(self.comboBoxColls.currentIndex()>0) if self.comboBoxCollections.currentIndex() > 0 and self.comboBoxDBs.currentIndex() > 0: #_dbName = str(self.comboBoxDBs.itemText(self.comboBoxDBs.currentIndex())) self.collection = str(self.comboBoxCollections.itemText(self.comboBoxCollections.currentIndex())) property = self.mongoUtil.get2dField(self.connection[self.db], self.collection) geo = self.mongoUtil.getSampleGeoValues(self.connection[self.db], self.collection) if type(geo) == types.ListType: self.comboBoxX.setEnabled(True) self.comboBoxY.setEnabled(True) self.comboBoxX.clear() self.comboBoxY.clear() self.x = '%s[0]' % property self.y = '%s[0]' % property self.comboBoxX.addItem(self.x) self.comboBoxY.addItem(self.y) else: self.setStatusText('TBD') """fields = [key for key in geo] self.labelLongitudeField.setEnabled(True) self.comboBoxLongField.setEnabled(True) self.comboBoxLongField.clear() self.comboBoxLongField.addItem(fields[0]) self.comboBoxLongField.addItem(fields[1]) if str(fields[0]).lower().startswith('lat'): self.comboBoxLongField.setCurrentIndex(1) self.labelLatitudeFieldName.setText(str(fields[0])) else: self.comboBoxLongField.setCurrentIndex(0) self.labelLatitudeFieldName.setText(str(fields[1]))""" def setStatusText(self, text): self.labelStatus.setText(text)