Exemple #1
0
	def reloadCollections(self) :
		"reloads the collection list."
		r = self.connection.session.get(self.collectionsURL)
		data = r.json()
		if r.status_code == 200 :
			self.collections = {}
			
			for colData in data["collections"] :
				colName = colData['name']
				if colData['isSystem'] :
					colObj = COL.SystemCollection(self, colData)
				else :
					try :
						colClass = COL.getCollectionClass(colName)
						# if colName[0] != "_" :
						colObj = colClass(self, colData)
					except KeyError :
						if colData["type"] == COL.COLLECTION_EDGE_TYPE :
							colObj = COL.Edges(self, colData)
						elif colData["type"] == COL.COLLECTION_DOCUMENT_TYPE :
							colObj = COL.Collection(self, colData)
						else :
							print("Warning!! Collection of unknown type: %d, trying to load it as Collection nonetheless." % colData["type"])
							colObj = COL.Collection(self, colData)

				self.collections[colName] = colObj
		else :
			raise updateError(data["errorMessage"], data)
Exemple #2
0
def getproduct(productid,companyid):
    time.sleep(0.1)
    urls = "http://www.directindustry.com/ajax/get-product-detail.html?productId=%s&companyId=%s&numCol=1"%(productid,companyid)
    tmp = collection.Collection(urls)
    tmp.add_header("X-Requested-With","XMLHttpRequest")
    html = tmp.get_content()
    return html
Exemple #3
0
    def get_collections(self):
        if self.user_url == None:
            print "I'm anonymous user."
            return
            yield
        else:
            collections_num = self.get_collections_num()
            if collections_num == 0:
                return
                yield
            else:
                for i in xrange((collections_num - 1) / 20 + 1):
                    collection_url = self.user_url + "/collections?page=" + str(
                        i + 1)

                    r = requests.get(collection_url)

                    soup = BeautifulSoup(r.content, "lxml")
                    for collection in soup.find_all(
                            "div", class_="zm-profile-section-item zg-clear"):
                        url = "http://www.zhihu.com" + \
                              collection.find("a", class_="zm-profile-fav-item-title")["href"]
                        name = collection.find(
                            "a",
                            class_="zm-profile-fav-item-title").string.encode(
                                "utf-8")
                        yield collection.Collection(url, name, self)
Exemple #4
0
def downimg(url,path="./"):
    filename=filenamereg.search(url).group(0)
    try:
        imgcontent=collection.Collection(url).content
        imgpath=open(path+filename,"wb")
        imgpath.write(imgcontent)
        imgpath.close()
    except BaseException,e:
        print e
Exemple #5
0
 def save_collections(self):
     # save all the collections of the user
     if self.url is None:
         print "Anonymous user, cannot save collections"
         return
     else:
         collection_url_list = self.get_collections_url()
         for collection_url in collection_url_list:
             collection.Collection(collection_url).save_questions_and_answers()
         return
Exemple #6
0
def main():
    col = c.Collection()
    params = createParser(col).parse_args(sys.argv[1:])

    if params.imp:
        col.reload(params.imp)

    if params.gui:
        GUI.main(col)

    col.archive()
Exemple #7
0
def report_info(root):
    import collection
    coll = collection.Collection(root)
    items = coll.get_type_counts().items()
    items.sort()
    total = 0
    for type, count in items:
        total = total + count
        print "%12s: %5d" % (type, count)
    print "%12s  -----" % ''
    print "%12s: %5d" % ("Total", total)
Exemple #8
0
def getproductid(companyname,companyid):
    time.sleep(0.1)
    urls = 'http://www.directindustry.com/prod/%s-%d.html'%(companyname.lower().replace(" ","-"),companyid)
    try:
        tmp = collection.Collection(urls)
        html = tmp.get_content()
    except:
        return False
    try:
        return productlistre.findall(html)
    except Exception,e:
        print e
        return False
    def post(self):
        current_user = users.get_current_user()

        if current_user:
            
            name = self.request.POST['birgun'];
            password = self.request.POST['birgpass'];
            cid = self.request.POST['birgcolid'];
            study_name = self.request.POST['gdRootCol'];
            
            c = collection.Collection()
            r = c.get_collection(cid,name,password)

            if r.status != 200:
                raise NoCollectionWithIDException('Failed to get the collection from BiRG')

            #email = '*****@*****.**' #raw_input('Google E-mail: ')
            #password = '******' #raw_input("Password: "******"Study name: ")

            # Assign the files to folders
            #helper = glims.Helper(email,password)
            
            helper = glims.Helper()
            potential_study_collections = helper.get_collections(study_name)

            if len(potential_study_collections) > 0:
                # Assume it is the one and only return (later this will have to be dynamic)
                study = glims.Study(helper,potential_study_collections[0]['entry'])
            else:
                study = glims.Study(helper,study_name)

            study.upload_files(c)
            
            # Report success.
            self.response.out.write("""<!DOCTYPE HTML>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <!-- Username: %s -->
        <p>A copy of collection #%d has been transferred from BiRG to Google Docs.</p>
    </body>
</html>
""" % (name,cid))

        else:
            self.redirect('https://%s/' % self.request.host)
Exemple #10
0
    def result(self, call):
        '''Getting learning outcomes and moving to the next card.
        
        Parameters
        ----------
        call : CallbackQuery
            Response to button press.
        '''

        minutes = int(call.data[-4:])
        status = datetime.datetime.now() + datetime.timedelta(minutes=minutes)
        card_key = re.findall(r'_\w-\d+-\d+-\w_(\w-\d+-\d+-\w)', call.data)[0]

        # Inserting a new result to the database.
        update = db.Update(call.message.chat.id, 'collections', 'card')
        update.card_attribute(card_key, 'status', status)

        training = collection.Collection(self.bot)
        training.continue_learning(call)
Exemple #11
0
    def __init__(self, parent, inst_main_num, instrument_name,
                 training_dirname, cache_dirname, final_dirname, judge_layout,
                 colls):
        QtGui.QFrame.__init__(self)

        self.inst_main_num = inst_main_num
        self.inst_type = instrument_numbers.DISTINCT_INSTRUMENT_NUMBERS[
            inst_main_num]
        if self.inst_type == 0:
            self.inst_num = self.inst_main_num - 0
        elif self.inst_type == 1:
            self.inst_num = self.inst_main_num - 5
        elif self.inst_type == 2:
            self.inst_num = self.inst_main_num - 7
        else:
            print "can't find inst num!"
        #print "string_instrument", self.inst_main_num, self.inst_type, self.inst_num

        self.instrument_name = instrument_name
        maininstname = instrument_name.split(" ")[0]
        self.files = dirs.ViviDirs(training_dirname, cache_dirname,
                                   final_dirname, maininstname)

        ### setup GUI
        self.ui = string_instrument_gui.Ui_string_instrument_gui()
        self.ui.setupUi(self)
        parent.addWidget(self)

        ### setup strings
        self.string_trains = []
        for st in range(NUM_STRINGS):
            if colls is None:
                coll = collection.Collection()
            else:
                coll = colls[st]
            st_train = string_train.StringTrain(self.layout(), st,
                                                self.inst_type, self.inst_num,
                                                self.files, judge_layout, coll)
            self.string_trains.append(st_train)
Exemple #12
0
def callback_query(call):
    try:
        handler = tools.Handler(bot)
        if handler.error(call.message):
            return

        elif call.data == 'profile':
            profile_menu(call)

        elif 'voice_mask' in call.data:
            change_voice_mask(call)

        elif 'collection' in call.data:
            collections = collection_py.Collections(bot)
            collection = collection_py.Collection(bot)

            if 'show' in call.data:
                collection.call_menu(call)

            elif 'create' in call.data:
                collections.create_collection(call)

            elif 'continue' in call.data:
                collection.continue_learning(call)

            elif 'rename' in call.data:
                collection.rename(call)

            elif 'delete' in call.data:
                if 'yes' in call.data:
                    collection.delete_yes(call)

                elif 'no' in call.data:
                    collection.delete_no(call)

                else:
                    collection.delete_menu(call)

            else:
                collections.call_menu(call)

        elif 'card' in call.data:
            cards = card_py.Cards(bot)
            card = card_py.Card(bot)

            if 'show' in call.data:
                card.call_menu(call)

            elif 'create' in call.data:
                cards.create_card(call)

            elif 'result' in call.data:
                card.result(call)

            elif 'continue' in call.data:
                card.start_learning(call)

            elif 'rename' in call.data:
                card.rename(call)

            elif 'description' in call.data:
                card.edit_description(call)

            elif 'info' in call.data:
                if 'on' in call.data:
                    card.info(call)
                else:
                    card.call_menu(call)

            elif 'delete' in call.data:
                if 'yes' in call.data:
                    card.delete_yes(call)

                elif 'no' in call.data:
                    card.delete_no(call)

                else:
                    card.delete_menu(call)

            else:
                cards.call_menu(call)

        elif call.data == 'home':
            home(call)
    except:
        bot.send_message(call.message.chat.id, messages.ASSISTANCE['LOADING'])
Exemple #13
0
def getproduct(productid,companyid):
    time.sleep(0.1)
    urls = "http://www.directindustry.com/ajax/get-product-detail.html?productId=%s&companyId=%s&numCol=1"%(productid,companyid)
    tmp = collection.Collection(urls)
    tmp.add_header("X-Requested-With","XMLHttpRequest")
    html = tmp.get_content()
    return html

if len(sys.argv) == 1:
    print "Max Input A KeyWord at Least"   
    exit()
else:
    for offset in range(len(sys.argv)-1):
        url = "http://www.directindustry.com/tab/%s.html"%sys.argv[offset+1].replace(" ","-")
        try:
            tmp  = collection.Collection(url)
            html = tmp.get_content()
        except Exception,e:
            print "Get %s Error,%s"%(url,e)

        #GET COMPANY
        companys = getcompany(html)
        if companys == False:
            continue
        for company in companys:
            companyname = company['companyname']
            companyid = company['companyid']
            products = getproductid(companyname,companyid)
            if products:
                sql = "insert into __companys (companyid,companyname,productsid) values (\"%s\",\"%s\",\"%s\");"%(companyid,companyname,",".join(products))
            else:
Exemple #14
0
# DCW -- Unused import?
#import getpass

import collection
import glims
glims = reload(glims)

c = collection.Collection()
name = raw_input("BiRG Username: "******"Password: "******"Collection ID: "))
r = c.get_collection(cid, name, password)

if r.status != 200:
    raise "Failed to get the collection"

email = '*****@*****.**'  #raw_input('Google E-mail: ')
password = '******'  #raw_input("Password: "******"Study name: ")

# Assign the files to folders
helper = glims.Helper(email, password)
potential_studies = helper.get_collections(study_name)
if len(potential_studies) > 0:
    study = glims.Study(
        helper, potential_studies[0]['entry']
    )  # Assume it is the one and only return (later this will have to be dynamic)
else:
    study = glims.Study(helper, study_name)

study.upload_files(c)
 def setup(self):
     pathtofixtures = "./fixtures/eads"
     smallead = "LAE003.EAD.xml"
     path = '/'.join((pathtofixtures, smallead))
     self.testee = collection.Collection(path)
Exemple #16
0
import pathlib

import api
import collection

# Project root.
ROOT_PATH = pathlib.Path(__file__).parent

# Storing data.
CARDS_DATA_PATH = ROOT_PATH.joinpath('data')  # Todo: Use database.
API = api.Scryfall(CARDS_DATA_PATH)

# Collection.
COLLECTION_PATH = ROOT_PATH.joinpath('collection')
COLLECTION = collection.Collection(COLLECTION_PATH, name='Collected')