Best Python code snippet using pyatom_python
graphs.py
Source:graphs.py
...467468 self._kwargs = kwargs469 470 self.version = version471 self.filedesc = self._get_key_value('fileDesc')472 self.profiledesc = self._get_key_value('profilDesc')473 self.datadesc = self._get_key_value('dataDesc')474475 def __repr__(self):476 return "StandoffHeader"477478 def _get_key_value(self, key):479 if key == 'fileDesc':480 return FileDesc()481 if key == 'profilDesc':482 return ProfileDesc()483 if key == 'dataDesc':484 return DataDesc(None)485486 return None487488489class FileDesc(object):490 """491 Class that represents the descriptions of the file492 containing the primary data document.493494 """495496 def __init__(self, **kwargs):497 """Class's constructor.498499 Parameters500 ----------501 titlestmt : str502 Name of the file containing the primary data503 document.504 extent : dict505 Size of the resource. The keys are 'count' -506 Value expressing the size. And 'unit' - Unit507 in which the size of the resource is expressed.508 Both keys are mandatory.509 title : str510 Title of the primary data document.511 author : dict512 Author of the primary data document. The keys513 are 'age' and 'sex'.514 source : dict515 Source from which the primary data was obtained.516 The keys are 'type' - Role or type the source517 with regard to the document. And 'source'. Both518 keys are mandatory.519 distributor : str520 Distributor of the primary data (if different521 from source).522 publisher : str523 Publisher of the source.524 pubAddress : str525 Address of publisher.526 eAddress : dict527 Email address, URL, etc. of publisher. The keys528 are 'email' and 'type' - Type of electronic529 address, such as email or URL. Both keys are530 mandatory.531 pubDate : str532 Date of original publication. Should use the533 ISO 8601 format YYYY-MM-DD.534 idno : dict535 Identification number for the document. The keys536 are 'number' and 'type' - Type of the identification537 number (e.g. ISBN). Both keys are mandatory.538 pubName : str539 Name of the publication in which the primary data was540 originally published (e.g. journal in which it appeared).541 documentation : str542 PID where documentation concerning the data may be found.543544 """545546 self._kwargs = kwargs547548 self.titlestmt = self._get_key_value('titlestmt')549 self.extent = self._get_key_value('extent')550 self.title = self._get_key_value('title')551 self.author = self._get_key_value('author')552 self.source = self._get_key_value('source')553 self.distributor = self._get_key_value('distributor')554 self.publisher = self._get_key_value('publisher')555 self.pubAddress = self._get_key_value('pubAddress')556 self.eAddress = self._get_key_value('eAddress')557 self.pubDate = self._get_key_value('pubDate')558 self.idno = self._get_key_value('idno')559 self.pubName = self._get_key_value('pubName')560 self.documentation = self._get_key_value('documentation')561562 def __repr__(self):563 return "FileDesc"564565 def _get_key_value(self, key):566 if key in self._kwargs:567 return self._kwargs[key]568569 return None570571572class ProfileDesc(object):573 """574 Class that represents the descriptions of the file575 containing the primary data document.576577 """578579 def __init__(self, **kwargs):580 """Class's constructor.581582 Parameters583 ----------584 catRef : str585 One or more categories defined in the resource586 header.587 subject : str588 Topic of the primary data.589 domain : str590 Primary domain of the data.591 subdomain : str592 Subdomain of the data.593 languages : array_like594 Array that contains the codes of the language(s)595 of the primary data. The codes should be in the596 ISO 639.597 participants : array_like598 Array that contains the participants in an599 interaction. Each person is a dict element and600 the keys are 'age', 'sex', 'role' and 'id' -601 Identifier for reference from annotation documents.602 The 'id' key is mandatory.603 settings : array_like604 Array that contains the settings within which a605 language interaction takes place. Each settings is606 a dictionary and the keys are 'who', 'time', 'activity'607 and 'locale'.608609 """610611 self._kwargs = kwargs612613 self.languages = self._get_key_value('languages')614 self.catRef = self._get_key_value('catRef')615 self.subject = self._get_key_value('subject')616 self.domain = self._get_key_value('domain')617 self.subdomain = self._get_key_value('subdomain')618 self.participants = self._get_key_value('participants')619 self.settings = self._get_key_value('settings')620621 def __repr__(self):622 return "ProfileDesc"623624 def add_language(self, language_code):625 """This method is responsible to add the626 annotations to the list of languages.627628 The language list in this class will629 represents the language(s) that the630 primary data use.631632 Parameters633 ----------634 language_code : str635 ISO 639 code(s) for the language(s) of the primary data.636637 """638639 self.languages.append(language_code)640641 def add_participant(self, id, age=None, sex=None, role=None):642 """This method is responsible to add the643 annotations to the list of participants.644645 The parcipant list in this class will646 represents participants in an interaction647 with the data manipulated in the files pointed648 by the header.649650 A participant is a person in this case and it's651 important and required to give the id.652653 Parameters654 ----------655 id : str656 Identifier for reference from annotation documents.657 age : int658 Age of the speaker.659 role : str660 Role of the speaker in the discourse.661 sex : str662 One of male, female, unknown.663664 """665666 participant = {'id': id}667668 if age:669 participant['age'] = age670 if sex:671 participant['sex'] = sex672 if role:673 participant['role'] = role674675 self.participants.append(participant)676677 def add_setting(self, who, time, activity, locale):678 """This method is responsible to add the679 annotations to the list of settings.680681 The setting list in this class will682 represents the setting or settings683 within which a language interaction takes684 place, either as a prose description or a685 series of setting elements.686687 A setting is a particular setting in which688 a language interaction takes place.689690 Parameters691 ----------692 who : str693 Reference to person IDs involved in this interaction.694 time : str695 Time of the interaction.696 activity : str697 What a participant in a language interaction is doing698 other than speaking.699 locale : str700 Place of the interaction, e.g. a room, a restaurant,701 a park bench.702703 """704705 self.settings.append({'who': who, 'time': time, 'activity': activity,706 'locale': locale})707708 def _get_key_value(self, key):709 if key in self._kwargs:710 return self._kwargs[key]711712 return None713714715class DataDesc(object):716 """717 Class that represents the annotations to the document associated718 with the primary data document this header describes.719720 """721722 def __init__(self, primaryData):
...
ebay.py
Source:ebay.py
...87 'startTime': item['listingInfo']['startTime'],88 'endTime': item['listingInfo']['endTime'],89 # item['location'],90 'paymentMethod': item['paymentMethod'],91 'postalCode': _get_key_value(item, 'postalCode'),92 'categoryId': item['primaryCategory']['categoryId'],93 'categoryName': item['primaryCategory']['categoryName'],94 'productId_type': _get_key_value(_get_key_value(item, 'productId'), '_type'),95 'productId_value': _get_key_value(_get_key_value(item, 'productId'), 'value'),96 'returnsAccepted': item['returnsAccepted'] == 'true',97 'value': float(item['sellingStatus']['currentPrice']['value']),98 'bidCount': _get_key_value(_get_key_value(item, 'sellingStatus'), 'bidCount'),99 'sellingState': item['sellingStatus']['sellingState'],100 'expeditedShipping': item['shippingInfo']['expeditedShipping'] == 'true',101 # 'handlingTime': item['shippingInfo']['handlingTime'],102 'shippingType': item['shippingInfo']['shippingType'],103 'title': item['title'],104 'topRatedListing': item['topRatedListing'] == 'true',105 'feedbackRatingStar': _get_key_value(_get_key_value(item, 'sellerInfo'), 'feedbackRatingStar'),106 'feedbackScore': _get_key_value(_get_key_value(item, 'sellerInfo'), 'feedbackScore'),107 'positiveFeedbackPercent': _get_key_value(_get_key_value(item, 'sellerInfo'),108 'positiveFeedbackPercent'),109 'topRatedSeller': _get_key_value(_get_key_value(item, 'sellerInfo'), 'topRatedSeller')}110 dicts.append(entry)111 return (pd.DataFrame(dicts))112def _get_key_value(dict, key):113 if key in dict:114 return (dict[key])115 else:116 return ('NA')117#######################################################118# API interface119#######################################################120def get_number_pages(opts, api_request):121 return int(_get_page(opts, api_request)['paginationOutput']['totalPages'])122# This gets up to 100 pages of items matching the API request123# Since each page can have up to 100 items, this call returns a maximum of124# 10,000 listings. This limit is enforced by the ebay API125def get_all_100(opts, api_request):126 num_pages = get_number_pages(opts, api_request)...
pipelines.py
Source:pipelines.py
...79 if res is not None:80 return res81 tx.execute('INSERT INTO `{}` (naziv) VALUES ("{}")'.format(tblname, value))82 return self._fetch_id(tx, tblname, value)83 def _get_key_value(self, adapter, keyname):84 return adapter[keyname][0] if keyname in adapter else None85 def _get_key_id(self, tx, tblname, adapter, keyname):86 return self._get_id(tx, tblname, adapter[keyname][0]) if keyname in adapter else None87 def _generate_insert_sql(self, data):88 columns = lambda d: ', '.join(['`{}`'.format(k) for k in d])89 placeholders = lambda d: ', '.join(['%s'] * len(d))90 values = lambda d: [v for v in d.values()]91 if self.upsert:92 sql_template = 'INSERT INTO `{}` ( {} ) VALUES ( {} ) ON DUPLICATE KEY UPDATE {}'93 on_duplicate_placeholders = lambda d: ', '.join(['`{}` = %s'.format(k) for k in d])94 return (95 sql_template.format(96 self.table, columns(data),97 placeholders(data), on_duplicate_placeholders(data)98 ),99 values(data) + values(data)100 )101 else:102 sql_template = 'INSERT INTO `{}` ( {} ) VALUES ( {} )'103 return (104 sql_template.format(self.table, columns(data), placeholders(data)),105 values(data)106 )107 def _generate_update_sql(self, data):108 sql_template = 'UPDATE `{}` SET udaljenost = {} WHERE id = "{}"'109 return sql_template.format(self.table, data['udaljenost'], data['id'])110 def _process_item(self, tx, item):111 if (is_item(item)):112 adapter = ItemAdapter(item)113 sqlItem = dict()114 sqlItem['id'] = self._get_key_value(adapter, 'id')115 if isinstance(item, Nekretnina):116 sqlItem['tip_id'] = self._get_key_id(tx, 'tip_nekretnine', adapter, 'tip')117 sqlItem['prodaja'] = self._get_key_value(adapter, 'prodaja')118 sqlItem['cena'] = self._get_key_value(adapter, 'cena')119 sqlItem['drzava_id'] = self._get_key_id(tx, 'drzava', adapter, 'drzava')120 sqlItem['grad_id'] = self._get_key_id(tx, 'grad', adapter, 'grad')121 sqlItem['deo_grada_id'] = self._get_key_id(tx, 'deo_grada', adapter, 'deo_grada')122 sqlItem['kvadratura'] = self._get_key_value(adapter, 'kvadratura')123 sqlItem['godina_izgradnje'] = self._get_key_value(adapter, 'godina_izgradnje')124 sqlItem['klasa_id'] = self._get_key_id(tx, 'klasa_izgradnje', adapter, 'klasa')125 sqlItem['povrsina_zemljista'] = self._get_key_value(adapter, 'povrsina_zemljista')126 sqlItem['ukupna_spratnost'] = self._get_key_value(adapter, 'ukupna_spratnost')127 sqlItem['sprat'] = self._get_key_value(adapter, 'sprat')128 sqlItem['uknjizenost'] = self._get_key_value(adapter, 'uknjizenost')129 sqlItem['tip_grejanja_id'] = self._get_key_id(tx, 'tip_grejanja', adapter, 'tip_grejanja')130 sqlItem['broj_soba'] = self._get_key_value(adapter, 'broj_soba')131 sqlItem['broj_kupatila'] = self._get_key_value(adapter, 'broj_kupatila')132 sqlItem['parking'] = self._get_key_value(adapter, 'parking')133 sqlItem['lift'] = self._get_key_value(adapter, 'lift')134 sqlItem['terasa'] = self._get_key_value(adapter, 'terasa')135 sql, data = self._generate_insert_sql(sqlItem)136 else:137 sqlItem['udaljenost'] = self._get_key_value(adapter, 'udaljenost')138 sql = self._generate_update_sql(sqlItem)139 try:140 if isinstance(item, Nekretnina):141 tx.execute(sql, data)142 else:143 tx.execute(sql)144 except pymysql.err.IntegrityError:145 # Duplicate entries are ignored...146 #147 pass148 except Exception:149 logger.error("SQL: %s", sql)150 raise151 self.stats.inc_value('{}/saved'.format(self.stats_name))
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!