async def welcomer_handler(self, member: discord.Member, ctx: CustomContext = None, background: str = None, fmt: int = None): guild = member.guild data = await Welcome().welcomer_data(self.bot, guild) warning = "" if not data["welcomer_enabled"] or not data["welcomer_channel"]: if not ctx: return warning += "You either don't have welcomer enabled or don't have a channel set so this will not work!" await ctx.send_error(warning) member_created = (datetime.utcnow() - member.created_at).days member_sign = "❌" if member_created == 0 else "⚠" if member_created <= 3 else "✅" channel = ctx.channel if ctx else self.bot.get_channel( data["welcomer_channel"]) color = await Guild().color(self.bot.pool, guild) background = background or data["welcomer_background"] fmt = fmt or data["welcomer_type"] content = self.build_message(data["welcomer_content"], member, guild) embed = data["welcomer_embed"] desc = [ f"{member_sign} Account created __**{member_created}**__ days ago!" if member_created else f"{member_sign} Account created __**Today!**__", f"🤖 __**Bot**__ account!" if member.bot else f"✅ __**User**__ account!" ] desc = '\n'.join(desc) em = discord.Embed(color=color, description=desc) if embed: em.set_thumbnail( url=guild.icon_url_as(static_format="png", size=1024)) em.set_image(url="attachment://welcome.png") else: if content: content += f"\n\n{desc}" else: content = desc params = { "type": fmt, "avatar": member.avatar_url_as(format="png"), "user_name": parse(str(member)), "guild_name": parse(guild.name), "member_count": guild.member_count, "color": hex(color).split('x')[-1] } if background: params["background"] = background image = await welcomer(self.bot.session, params) try: return await channel.send(file=discord.File( fp=image, filename="welcome.png"), embed=em if embed else None, content=content) except (discord.Forbidden, AttributeError): await Welcome().disable(self.bot, guild)
def load_results(self): print("Searching lyrics for [{}]...".format(self.search_term)) for url in search(self.search_term, tld='com.pk', lang='en', stop=10): if parse(url).hostname == 'www.animelyrics.com': self._parse_animelyrics(url) return elif parse(url).hostname == 'www.letras.com' or parse( url).hostname == 'www.letras.mus.br' and url.count( 'traducao') == 0: self._parse_letras(url) return elif parse(url).hostname == 'www.smule.com': self._parse_smule(url) return print("Searching lyrics for [{}] (2nd try)...".format( self.search_term)) for url in search(self.search_term + ' lyrics', tld='com.pk', lang='en', stop=10): if parse(url).hostname == 'www.animelyrics.com': self._parse_animelyrics(url) return elif parse(url).hostname == 'www.letras.com' or parse( url).hostname == 'www.letras.mus.br' and url.count( 'traducao') == 0: self._parse_letras(url) return elif parse(url).hostname == 'www.smule.com': self._parse_smule(url) return
def do_GET(self): req = parse(self.path) if req.path in '/version': self.wfile.write(API.VERSION) # get metric elif req.path in API.METRIC_GET_URLS: query = parse_qs(req.query) key, host = None, None if 'key' in query: key = query['key'][0] if 'host' in query: host = query['host'][0] resp = self.sender.get_metric(key, host) if resp[0] is not None: result = '{0}\t{1}\t{2}'.format( key, resp[0], resp[1]) if platform.PY3: result = bytearray(result, 'utf-8') self.wfile.write(result) else: self.wfile.write(API.METRIC_NOT_FOUND) # get list of metric elif req.path in API.METRIC_LIST_URLS: query, host, result = parse_qs(req.query), None, '' if 'host' in query: host = query['host'][0] for val in self.sender.list_metrics(host): result += '{0}\t{1}\t{2}\n'.format( val[0], val[1][0], val[1][1]) if platform.PY3: result = bytearray(result, 'utf-8') self.wfile.write(result) else: # unknown path self.wfile.write(API.UNKNOWN_VERSION)
def query_rule(self, sentence): #query_analyser = intelligentDrawing.BasedQueryAnalyser() parse = Parse() result = parse.parse(sentence) #result = parse.parseByRule(sentence) return result
def sentSearch(self, url): if py3k: if not isinstance(url, str): raise TwitterSearchException(1009) else: if not isinstance(url, basestring): raise TwitterSearchException(1009) r = requests.get(self.base_url + self.search_url + url, auth=self.__oauth) self._response['meta'] = r.headers self.checkHTTPStatus(r.status_code) # using IDs to request more results - former versions used page parameter # see https://dev.twitter.com/docs/working-with-timelines given_count = int(parse(url)['count'][0]) self._response['content'] = r.json() self._statistics['queries'] += 1 self._statistics['tweets'] += len(self._response['content']['statuses']) if int(self._response['content']['search_metadata']['count']) == given_count: # have a look for the lowest ID for tweet in self._response['content']['statuses']: if tweet['id'] < self._nextMaxID: self._nextMaxID = tweet['id'] self._nextMaxID -= 1 else: self._nextMaxID = None return self._response['meta'], self._response['content']
def maybe_market_kudos_to_github(kt): """Post a Github comment for the specified Kudos. Args: kt (kudos.models.KudosTransfer): The KudosTransfer to be marketed. Returns: bool: Whether or not the Github comment was posted successfully. """ if not kt.is_notification_eligible(var_to_check=settings.GITHUB_CLIENT_ID) or not kt.github_url: return False # prepare message username = kt.username if '@' in kt.username else f'@{kt.username}' _from = f" from @{kt.from_username}" if kt.from_name else "" warning = kt.network if kt.network != 'mainnet' else "" _comments = "\n\nThe sender had the following public comments: \n> " \ f"{kt.comments_public}" if kt.comments_public else "" if kt.username: msg = f"тЪбя╕П A *{kt.kudos_token_cloned_from.humanized_name}* Kudos has been " \ f"sent to {username} for this issue{_from}. тЪбя╕П {_comments}\n\nNice work {username}! " redeem_instructions = "\nTo redeem your Kudos, login to Gitcoin at https://gitcoin.co/explorer and select " \ "'Claim Kudos' from dropdown menu in the top right, or check your email for a " \ "link to the Kudos redemption page. " if kt.receive_txid: redeem_instructions = "\nYour Kudos has automatically been sent in the ETH address we have on file." msg += redeem_instructions else: # TODO: support this once ETH-only sends are done return False image = f"<a title='{kt.kudos_token_cloned_from.humanized_name}' href='{kt.kudos_token_cloned_from.url}'> " \ f"<img width='250' src='{kt.kudos_token_cloned_from.img_url}' " \ f"alt='{kt.kudos_token_cloned_from.humanized_name}'> " \ f"</a> " msg = f""" <table> <tr> <td> {image} </td> <td> {msg} </td> </tr> </table>""" # actually post url = kt.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] post_issue_comment(username, repo, issue_num, msg) except Exception as e: print(e) return False return True
def maybe_market_tip_to_github(tip): if not settings.GITHUB_CLIENT_ID: return False if not tip.github_url: return False if tip.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False # prepare message username = tip.username if '@' in tip.username else str('@' + tip.username) _from = " from {}".format(tip.from_name) if tip.from_name else "" warning = tip.network if tip.network != 'mainnet' else "" _comments = "\n\nThe sender had the following public comments: \n> {}".format(tip.comments_public) if tip.comments_public else "" msg = "⚡️ A tip worth {} {} {} {} has been granted to {} for this issue{}. ⚡️ {}\n\nNice work {}, check your email for further instructions. \n\n * ${} in Funded OSS Work Available at: https://gitcoin.co/explorer\n * Incentivize contributions to your repo: <a href='https://gitcoin.co/tip'>Send a Tip</a> or <a href='https://gitcoin.co/funding/new'>Fund a PR</a>\n * No Email? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>" msg = msg.format(round(tip.amount, 3), warning, tip.tokenName, "(${})".format(tip.value_in_usdt) if tip.value_in_usdt else "" , username, _from, _comments, username, amount_usdt_open_work()) # actually post url = tip.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] post_issue_comment(username, repo, issue_num, msg) except Exception as e: print(e) return False return True
def do_GET(self): self._set_header() req = parse(self.path) if req.path in '/version': self.wfile.write(API.VERSION) # get metric elif req.path in API.METRIC_GET_URLS: query = parse_qs(req.query) key, host = None, None if 'key' in query: key = query['key'][0] if 'host' in query: host = query['host'][0] resp = self.sender.get_metric(key, host) if resp[0] is not None: result = '{0}\t{1}\t{2}'.format(key, resp[0], resp[1]) result = bytearray(result, 'utf-8') self.wfile.write(result) else: self.wfile.write(API.METRIC_NOT_FOUND) # get list of metric elif req.path in API.METRIC_LIST_URLS: query, host, result = parse_qs(req.query), None, '' if 'host' in query: host = query['host'][0] for val in self.sender.list_metrics(host): result += '{0}\t{1}\t{2}\n'.format(val[0], val[1][0], val[1][1]) result = bytearray(result, 'utf-8') self.wfile.write(result) else: # unknown path self.wfile.write(API.UNKNOWN_VERSION)
def maybe_market_tip_to_github(tip): """Post a Github comment for the specified Tip. Args: tip (dashboard.models.Tip): The Tip to be marketed. Returns: bool: Whether or not the Github comment was posted successfully. """ if not tip.is_notification_eligible( var_to_check=settings.GITHUB_CLIENT_ID) or not tip.github_url: return False # prepare message username = tip.username if '@' in tip.username else f'@{tip.username}' _from = f" from @{tip.from_username}" if tip.from_name else "" warning = tip.network if tip.network != 'mainnet' else "" _comments = "\n\nThe sender had the following public comments: \n> " \ f"{tip.comments_public}" if tip.comments_public else "" try: value_in_usd = f"({tip.value_in_usdt_now} USD @ ${round(convert_token_to_usdt(tip.tokenName), 2)}/{tip.tokenName})" if tip.value_in_usdt_now else "" except Exception: pass # no USD conv rate if tip.username: msg = f"⚡️ A tip worth {round(tip.amount, 5)} {warning} {tip.tokenName} {value_in_usd} has been " \ f"granted to {username} for this issue{_from}. ⚡️ {_comments}\n\nNice work {username}! " redeem_instructions = "To redeem your tip, login to Gitcoin at https://gitcoin.co/explorer and select " \ "'Claim Tip' from dropdown menu in the top right, or check your email for a " \ "link to the tip redemption page. " if tip.receive_txid: redeem_instructions = "Your tip has automatically been deposited in the ETH address we have on file." addon_msg = f"\n\n * ${amount_usdt_open_work()} in Funded OSS Work Available at: " \ f"https://gitcoin.co/explorer\n * Incentivize contributions to your repo: " \ f"<a href='https://gitcoin.co/tip'>Send a Tip</a> or <a href='https://gitcoin.co/funding/new'>" \ f"Fund a PR</a>\n * No Email? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>" msg += redeem_instructions + addon_msg else: msg = f"💰 A crowdfund contribution worth {round(tip.amount, 5)} {warning} {tip.tokenName} {value_in_usd} has " \ f"been attached to this funded issue {_from}.💰 {_comments}\n" if tip.bounty: msg += f"\nWant to chip in also? Add your own contribution [here]({tip.bounty.absolute_url})." # actually post url = tip.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] post_issue_comment(username, repo, issue_num, msg) except Exception as e: print(e) return False return True
def setSearchURL(self, url): if url[0] == '?': url = url[1:] args = parse(url) self.searchterms = args['q'] del args['q'] self.arguments = {} for key, value in args.items(): self.arguments.update({key : value[0]})
def parse_text(pattern, text): """Parse a pattern from https://pypi.python.org/pypi/parse Returns the parse.Result object. Raises an exception if no match. """ result = parse.parse(pattern, text.strip()) if not result: raise ValueError(f"Couldn't apply pattern {pattern!r} to {text!r}") return result
def domain_to_ip(url): # url = 'www.stackoverflow.com/questions/43469412/convert-html-source-code-to-json-object' if (url.find('//www.', 0, 15) >= 0): url1 = parse(url) domain_ip = socket.gethostbyname(url1.netloc) domain_name_temp = url1.netloc domain_name_list = domain_name_temp.split('.', 1) domain_name = domain_name_list[1] html_page = requests.get(url) elif (url.find('//', 0, 15) >= 0): url1 = parse(url) domain_ip = socket.gethostbyname(url1.netloc) domain_name = url1.netloc html_page = requests.get(url) elif (url.find('www.', 0, 4) >= 0): url_temp = url.split('.', 1) url = 'http://' + url url1 = parse(url) domain_ip = socket.gethostbyname(url1.netloc) domain_name_temp = url1.netloc domain_name_list = domain_name_temp.split('.', 1) domain_name = domain_name_list[1] html_page = requests.get(url) else: url = 'http://' + url url1 = parse(url) domain_ip = socket.gethostbyname(url1.netloc) domain_name = url1.netloc html_page = requests.get(url) return {"url": url, "domain_ip": domain_ip, "domain_name": domain_name}
def parseQuestionUrl(url): val = URLValidator() try: val(url) except ValidationError: return False arr = parse(url) pathSections = arr.path.split('/') try: id = int(pathSections[2]) except ValueError: return False return id
def execute(args=None): """Executes a command specified by args. Keyword arguments: args -- represents the command to be executed (default: None that is the command is read from stdin) """ info = parse.parse(OscCommand, args) apiurl = 'api' if 'apiurl' in info: apiurl = info.apiurl info.set('apiurl', _init(apiurl)) info.func(info)
def notdupeextract(primarySource, headers, doc): if not 'nodescription' in os.environ: desc = parse.parse(doc['description']).strip() if desc: yield Description(desc) yield Source(doc['source_url']) for tag in doc['tags'].split(', '): if ':' in tag: yield Tag(*tag.split(':',1)) else: yield Tag(None, tag) yield Name(doc['file_name']) # yield Type(doc['mime_type']) this gets sent during the request anyway yield Media(doc['image'].replace("/view/","/download/"))
def maybe_market_tip_to_github(tip): """Post a Github comment for the specified Tip. Args: tip (dashboard.models.Tip): The Tip to be marketed. Returns: bool: Whether or not the Github comment was posted successfully. """ if (not settings.GITHUB_CLIENT_ID) or (not tip.github_url) or ( tip.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK): return False # prepare message username = tip.username if '@' in tip.username else f'@{tip.username}' _from = f" from {tip.from_name}" if tip.from_name else "" warning = tip.network if tip.network != 'mainnet' else "" _comments = "\n\nThe sender had the following public comments: \n> " \ f"{tip.comments_public}" if tip.comments_public else "" try: value_in_usd = f"({tip.value_in_usdt_now} USD @ ${round(convert_token_to_usdt(tip.tokenName), 2)}/{tip.tokenName})" if tip.value_in_usdt_now else "" except Exception: pass # no USD conv rate msg = f"⚡️ A tip worth {round(tip.amount, 5)} {warning} {tip.tokenName} {value_in_usd} has been " \ f"granted to {username} for this issue{_from}. ⚡️ {_comments}\n\nNice work {username}! To " \ "redeem your tip, login to Gitcoin at https://gitcoin.co/explorer and select 'Claim Tip' " \ "from dropdown menu in the top right, or check your email for a link to the tip redemption " \ f"page. \n\n * ${amount_usdt_open_work()} in Funded OSS Work Available at: " \ "https://gitcoin.co/explorer\n * Incentivize contributions to your repo: " \ "<a href='https://gitcoin.co/tip'>Send a Tip</a> or <a href='https://gitcoin.co/funding/new'>" \ "Fund a PR</a>\n * No Email? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>" # actually post url = tip.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] post_issue_comment(username, repo, issue_num, msg) except Exception as e: print(e) return False return True
def maybe_market_tip_to_github(tip): """Post a Github comment for the specified Tip. Args: tip (dashboard.models.Tip): The Tip to be marketed. Returns: bool: Whether or not the Github comment was posted successfully. """ if not settings.GITHUB_CLIENT_ID: return False if not tip.github_url: return False if tip.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False # prepare message username = tip.username if '@' in tip.username else str('@' + tip.username) _from = " from {}".format(tip.from_name) if tip.from_name else "" warning = tip.network if tip.network != 'mainnet' else "" _comments = "\n\nThe sender had the following public comments: \n> {}".format( tip.comments_public) if tip.comments_public else "" msg = "⚡️ A tip worth {} {} {} {} has been granted to {} for this issue{}. ⚡️ {}\n\nNice work {}! To redeem your tip, login to Gitcoin at https://gitcoin.co/explorer and select 'Claim Tip' from dropdown menu in the top right, or check your email for a link to the tip redemption page. \n\n * ${} in Funded OSS Work Available at: https://gitcoin.co/explorer\n * Incentivize contributions to your repo: <a href='https://gitcoin.co/tip'>Send a Tip</a> or <a href='https://gitcoin.co/funding/new'>Fund a PR</a>\n * No Email? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>" msg = msg.format( round(tip.amount, 5), warning, tip.tokenName, "(${})".format(tip.value_in_usdt) if tip.value_in_usdt else "", username, _from, _comments, username, amount_usdt_open_work()) # actually post url = tip.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] post_issue_comment(username, repo, issue_num, msg) except Exception as e: print(e) return False return True
def csv_to_domain_ip(url_data): response_str = '' df_urls = pd.read_csv(url_data, header=None, names=['url']) df_data = pd.DataFrame(columns=[ 'domain_name', 'domain_ip', 'url', 'json_object', 'date', 'time' ]) for url in df_urls['url']: if (url.find('//www.', 0, 15) >= 0): url1 = parse(url) domain_ip = socket.gethostbyname(url1.netloc) domain_name_temp = url1.netloc domain_name_list = domain_name_temp.split('.', 1) domain_name = domain_name_list[1] html_page = requests.get(url) current_date = (str(datetime.datetime.now())).split(' ')[0] current_time = (str(datetime.datetime.now())).split(' ')[1].split( '.', 1)[0] json_object = json.dumps({ 'url': str(url), 'uid': str(1024), 'page_content': html_page.text, 'date_time': str(datetime.datetime.now()) }) elif (url.find('//', 0, 15) >= 0): url1 = parse(url) domain_ip = socket.gethostbyname(url1.netloc) domain_name = url1.netloc html_page = requests.get(url) current_date = (str(datetime.datetime.now())).split(' ')[0] current_time = (str(datetime.datetime.now())).split(' ')[1].split( '.', 1)[0] json_object = json.dumps({ 'url': str(url), 'uid': str(1024), 'page_content': html_page.text, 'date_time': str(datetime.datetime.now()) }) elif (url.find('www.', 0, 4) >= 0): url_temp = url.split('.', 1) url = 'http://' + url url1 = parse(url) domain_ip = socket.gethostbyname(url1.netloc) domain_name_temp = url1.netloc domain_name_list = domain_name_temp.split('.', 1) domain_name = domain_name_list[1] html_page = requests.get(url) current_date = (str(datetime.datetime.now())).split(' ')[0] current_time = (str(datetime.datetime.now())).split(' ')[1].split( '.', 1)[0] json_object = json.dumps({ 'url': str(url), 'uid': str(1024), 'page_content': html_page.text, 'date_time': str(datetime.datetime.now()) }) else: url = 'http://' + url url1 = parse(url) domain_ip = socket.gethostbyname(url1.netloc) domain_name = url1.netloc html_page = requests.get(url) current_date = (str(datetime.datetime.now())).split(' ')[0] current_time = (str(datetime.datetime.now())).split(' ')[1].split( '.', 1)[0] json_object = json.dumps({ 'url': str(url), 'uid': str(1024), 'page_content': html_page.text, 'date_time': str(datetime.datetime.now()) }) #print(url) #print(domain_ip) #print(domain_name) #print(current_date) #print(current_time) response_str = response_str + '\n' + domain_name + '\t' + domain_ip + '\n' df_data = df_data.append( { 'domain_name': domain_name, 'domain_ip': domain_ip, 'url': url, 'json_object': json_object, 'date': current_date, 'time': current_time }, ignore_index=True) return response_str
def maybe_market_to_github(bounty, event_name, profile_pairs=None): """Post a Github comment for the specified Bounty. Args: bounty (dashboard.models.Bounty): The Bounty to be marketed. event_name (str): The name of the event. profile_pairs (list of tuples): The list of username and profile page URL tuple pairs. Returns: bool: Whether or not the Github comment was posted successfully. """ if not bounty.is_notification_eligible( var_to_check=settings.GITHUB_CLIENT_ID): return False # Define posting specific variables. comment_id = None url = bounty.github_url uri = parse(url).path uri_array = uri.split('/') # Prepare the comment message string. msg = build_github_notification(bounty, event_name, profile_pairs) if not msg: return False try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] if event_name == 'work_started': comment_id = bounty.interested_comment elif event_name in ['work_done', 'work_submitted']: comment_id = bounty.submissions_comment # Handle creating or updating comments if profiles are provided. if event_name in ['work_started', 'work_submitted'] and profile_pairs: if comment_id is not None: patch_issue_comment(comment_id, username, repo, msg) else: response = post_issue_comment(username, repo, issue_num, msg) if response.get('id'): if event_name == 'work_started': bounty.interested_comment = int(response.get('id')) elif event_name in ['work_done', 'work_submitted']: bounty.submissions_comment = int(response.get('id')) bounty.save() # Handle deleting comments if no profiles are provided. elif event_name in ['work_started'] and not profile_pairs: if comment_id: delete_issue_comment(comment_id, username, repo) if event_name == 'work_started': bounty.interested_comment = None elif event_name == 'work_done': bounty.submissions_comment = None bounty.save() # If this isn't work_started/done, simply post the issue comment. else: post_issue_comment(username, repo, issue_num, msg) except IndexError: return False except Exception as e: extra_data = { 'github_url': url, 'bounty_id': bounty.pk, 'event_name': event_name } logger.error('Failure in marketing to github', exc_info=True, extra=extra_data) print(e) return False return True
def maybe_market_to_github(bounty, event_name, txid=None, interested=None): if not settings.GITHUB_CLIENT_ID: return False if bounty.get_natural_value() < 0.0001: return False if bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False # prepare message msg = '' usdt_value = "(" + str(round(bounty.value_in_usdt, 2)) + " USD)" if bounty.value_in_usdt else "" if event_name == 'new_bounty': msg = "__This issue now has a funding of {} {} {} attached to it.__\n\n * If you would like to work on this issue you can claim it [here]({}).\n * If you've completed this issue and want to claim the bounty you can do so [here]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, bounty.get_absolute_url(), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'killed_bounty': msg = "__The funding of {} {} {} attached to this issue has been **killed** by the bounty submitter__\n\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, amount_usdt_open_work(), ) elif event_name == 'rejected_claim': msg = "__This fulfillment for the funding of {} {} {} attached to this issue has been **rejected** and can now be fulfilled by someone else.__\n\n * If you would like to work on this issue you can claim it [here]({}).\n * If you've completed this issue and want to claim the bounty you can do so [here]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, bounty.get_absolute_url(), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'new_interest': msg = "__The funding of {} {} {} attached has been shown interest by: {}.__ {} \n\n * Learn more [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" # Build interested profiles string. interested_profiles = ", ".join("[@%s](%s)" % interest for interest in interested) msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, interested_profiles if interested_profiles else "", "\n\n If you are interested, please leave a comment to let the funder {} and the other parties involved why you're interested in working on this issue and your plans to resolve it. If you don't leave a comment, the funder may not think you're too interested.".format( "(@{})".format(bounty.bounty_owner_github_username) if bounty.bounty_owner_github_username else "", ), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'new_claim': msg = "__The funding of {} {} {} attached has been fulfilled {}.__ {} \n\n * Learn more [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, "by @{}".format(bounty.claimee_github_username) if bounty.claimee_github_username else "", "\n\n {}, please leave a comment to let the funder {} (and the other parties involved) that you've fulfilled the bounty. If you don't leave a comment, the funder may expire your claim at their discretion.".format( "@{}".format(bounty.claimee_github_username) if bounty.claimee_github_username else "If you are the claimee", "(@{})".format(bounty.bounty_owner_github_username) if bounty.bounty_owner_github_username else "", ), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'approved_claim': msg = "__The funding of {} {} {} attached to this issue has been approved & issued {}.__ \n\n * Learn more at [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, "to @{}".format(bounty.claimee_github_username) if bounty.claimee_github_username else "", bounty.get_absolute_url(), amount_usdt_open_work(), ) else: return False # actually post url = bounty.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] if event_name == 'new_interest' and interested: if bounty.interested_comment is not None: patch_issue_comment(bounty.interested_comment, username, repo, msg) else: response = post_issue_comment(username, repo, issue_num, msg) if response.get('id'): bounty.interested_comment = response.get('id') bounty.save() elif event_name == 'new_interest' and not interested: delete_issue_comment(bounty.interested_comment, username, repo) bounty.interested_comment = None bounty.save() else: post_issue_comment(username, repo, issue_num, msg) except Exception as e: extra_data = {'github_url': url, 'bounty_id': bounty.pk, 'event_name': event_name} rollbar.report_exc_info(sys.exc_info(), extra_data=extra_data) print(e) return False return True
def accept(self, url: str): return parse(url).hostname in self.urls
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from celery import Task from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.exc import SQLAlchemyError from flask import current_app as app from boto3 import client from urllib.parse import parse queue_url = parse('SQS_QUEUE_URL') from ..models import Contact from . import mq class SqlTask(Task): """ abstract task that ensures the db connection is closed after execution """ abstract = True def after_return(self, status, retval, task_id, args, kwargs, einfo): session = app.data.driver.session session.remove() @mq.task(base=SqlTask, max_retries=10, default_retry_delay=60) def get_contact_from_database(contact_id): session = app.data.driver.session
def maybe_market_to_github(bounty, event_name, interested=None): """Post a Github comment for the specified Bounty. Args: bounty (dashboard.models.Bounty): The Bounty to be marketed. event_name (str): The name of the event. interested (list of tuples): The list of username and profile page URL tuple pairs. Returns: bool: Whether or not the Github comment was posted successfully. """ if not settings.GITHUB_CLIENT_ID: return False if bounty.get_natural_value() < 0.0001: return False if bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False # prepare message msg = '' usdt_value = "(" + str(round(bounty.value_in_usdt, 2)) + " USD)" if bounty.value_in_usdt else "" if event_name == 'new_bounty': msg = "__This issue now has a funding of {} {} {} attached to it.__\n\n * If you would like to work on this issue you can claim it [here]({}).\n * If you've completed this issue and want to claim the bounty you can do so [here]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, bounty.get_absolute_url(), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'killed_bounty': msg = "__The funding of {} {} {} attached to this issue has been **killed** by the bounty submitter__\n\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, amount_usdt_open_work(), ) elif event_name == 'rejected_claim': msg = "__The work submission for {} {} {} has been **rejected** and can now be submitted by someone else.__\n\n * If you would like to work on this issue you can claim it [here]({}).\n * If you've completed this issue and want to claim the bounty you can do so [here]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, bounty.get_absolute_url(), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'work_started': msg = "__Work has been started on the {} {} {} funding by__: \n 1. {} {} \n\n * Learn more [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" # Build interested profiles string. interested_profiles = "\n 1. ".join("[@%s](%s)" % interest for interest in interested) msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, interested_profiles if interested_profiles else "", "\n\n __Please work together__ and coordinate delivery of the issue scope. Gitcoin doesn't know enough about everyones skillsets / free time to say who should work on what, but we trust that the community is smart and well-intentioned enough to work together. As a general rule; if you start work first, youll be at the top of the above list ^^, and should have 'dibs' as long as you follow through. \n\n On the above list? Please leave a comment to let the funder {} and the other parties involved what you're working, with respect to this issue and your plans to resolve it. If you don't leave a comment, the funder may expire your submission at their discretion." .format( "(@{})".format(bounty.bounty_owner_github_username) if bounty.bounty_owner_github_username else "", ), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'work_submitted': msg = "__Work for {} {} {} has been submitted {}.__ {} \n\n * Learn more [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, "by @{}".format(bounty.fulfiller_github_username) if bounty.fulfiller_github_username else "", "\n\n {}, please leave a comment to let the funder {} (and the other parties involved) that you've submitted you work. If you don't leave a comment, the funder may expire your submission at their discretion." .format( "@{}".format(bounty.fulfiller_github_username) if bounty.fulfiller_github_username else "If you are the claimee", "(@{})".format(bounty.bounty_owner_github_username) if bounty.bounty_owner_github_username else "", ), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'work_done': msg = "__The funding of {} {} {} attached to this issue has been approved & issued {}.__ \n\n * Learn more at [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, "to @{}".format(bounty.fulfiller_github_username) if bounty.fulfiller_github_username else "", bounty.get_absolute_url(), amount_usdt_open_work(), ) else: return False # actually post url = bounty.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] if event_name == 'work_started' and interested: if bounty.interested_comment is not None: patch_issue_comment(bounty.interested_comment, username, repo, msg) else: response = post_issue_comment(username, repo, issue_num, msg) if response.get('id'): bounty.interested_comment = int(response.get('id')) bounty.save() elif event_name == 'work_started' and not interested: delete_issue_comment(bounty.interested_comment, username, repo) bounty.interested_comment = None bounty.save() else: post_issue_comment(username, repo, issue_num, msg) except Exception as e: extra_data = { 'github_url': url, 'bounty_id': bounty.pk, 'event_name': event_name } rollbar.report_exc_info(sys.exc_info(), extra_data=extra_data) print(e) return False return True
# Overridable -- handle declaration def handle_decl(self, decl): pass # Overridable -- handle processing instruction def handle_pi(self, data): if debug: print("pi: %s" % data) pass def getDom(self): return self.rootDom onlyOneTag = ("br", "hr", "img", "link", "meta", "input") def oneTag(tag): return tag in onlyOneTag if __name__ == "__main__": debug = True path = r"C:\Users\Thinkpad\Desktop\a.txt" path = r"C:\Users\leihuating\Desktop\a" ps = HtmlDomParser('https://tools.ietf.org/html/rfc2616#section-14.17') ps.setData(open(path, encoding="utf-8").read()) dom = ps.parse() print(dom.toHtml())
def accept(self, url: str): return parse(url).hostname in self.urls and url.count("traducao") == 0