Best Python code snippet using lisa_python
ff.py
Source: ff.py
...13with open("../data/" + name + ".json") as f:14 graph_data = json.load(f)15graph_data["data"]["user"]["login"]16#%%17def get_username(data: dict):18 return data["login"]19def get_data(data: dict) -> tuple:20 return (data["login"], {"company": data["company"]})21def has_atmark(x: dict) -> bool:22 return x != {} and x["company"] != None # and x["company"].find("@") != -123def filter_only_atmark(data: List[dict]) -> List[dict]:24 return list(filter(has_atmark, data))25def get_followers_list(data: dict) -> List[dict]:26 return list(filter(has_atmark, data["followers"]["nodes"]))27def get_following_list(data: dict) -> List[dict]:28 return list(filter(has_atmark, data["following"]["nodes"]))29#%%30# 0次31nodes: List[tuple] = []32user1 = graph_data["data"]["user"]33# 1次34followers1 = get_followers_list(user1)35for follower1 in followers1:36 nodes.append((get_data(follower1)))37 # nx.add_path(G, [get_username(follower1), get_username(user1)])38followings1 = get_following_list(user1)39for following1 in followings1:40 nodes.append((get_data(following1)))41 # nx.add_path(G, [get_username(user1), get_username(following1)])42# 2次43for follower1 in followers1:44 followers2 = get_followers_list(follower1)45 for follower2 in followers2:46 nodes.append((get_data(follower2)))47 if get_username(follower2) != get_username(user1):48 nx.add_path(G, [get_username(follower2), get_username(follower1)])49 followings2 = get_following_list(follower1)50 for following2 in followings2:51 nodes.append((get_data(following2)))52 if get_username(following2) != get_username(user1):53 nx.add_path(G, [get_username(following2), get_username((follower1))])54for following1 in followings1:55 followers2 = get_followers_list(following1)56 for follower2 in followers2:57 nodes.append((get_data(follower2)))58 if get_username(follower2) != get_username(user1):59 nx.add_path(G, [get_username(follower2), get_username(following1)])60 followings2 = get_following_list(following1)61 for following2 in followings2:62 nodes.append((get_data(following2)))63 if get_username(following2) != get_username(user1):64 nx.add_path(G, [get_username(following2), get_username(following1)])65G.add_nodes_from(nodes)66print(G.nodes.data().__len__()) # 24367#%% export68nx.write_gexf(G, "../data/" + name + ".gexf")...
backend.py
Source: backend.py
1from flask import Flask, jsonify, request, abort2from pymongo import MongoClient3import cryptograph4import configparser5config = configparser.ConfigParser()6config.read('mongodb.ini')7app = Flask(__name__)8mongo = MongoClient('mongodb://' + config['mongo']['IP'] + ':' + config['mongo']['PORT'] + '/')9mongodb = mongo.cryptoapi10@app.route('/messages/<string:username>/list', methods=['GET'])11def get_messages(username):12 mongoget = mongodb.messages13 get_username = mongoget.find_one({'owner': username})14 output = []15 if get_username:16 cryptoinit = cryptograph.Crypto(username, email=get_username["email"])17 decryptmessage = cryptoinit.decryptdata(get_username['message'])18 output.append({'owner': get_username['owner'], 'enc_message': decryptmessage, 'sender': get_username['sender'], 'time': get_username['time']})19 return jsonify({'messages': output})20 else:21 print("Wrong User!!!")22 return abort(404)23@app.route('/messages/<string:username>/list', methods=['POST'])24def set_messages(username, email):25 mongoget = mongodb.messages26 get_username = mongoget.find_one({'owner': username})27 output = []28 if get_username:29 cryptoinit = cryptograph.Crypto(username, email)30 encryptmessage = cryptoinit.encryptdata(get_username['message'], username)31 output.append({'owner': get_username['owner'], 'enc_message': encryptmessage, 'sender': get_username['sender'], 'time': get_username['time']})32 return jsonify({'messages': output})33 else:34 print("Wrong User!!!")35 return abort(404)36@app.route('/messages/<string:username>/key', methods=['GET'])37def get_user_key(username):38 mongoget = mongodb.tasks39 get_username = mongoget.find_one({'user': username})40@app.route('/messages/<string:username>/key', methods=['POST'])41def set_user_key(username, email):42 if not request.json or 'username' not in request.json:43 abort(400)44 mongopost = mongodb.keys45 cryptoinit = cryptograph.Crypto(username, email)46 jobpost = {47 'user': request.json['title'],48 'pubkey': request.json.get(cryptoinit.export_public(), ""),49 }50 mongopost.insert_one(jobpost)51 return jsonify(str(jobpost)), 20152if __name__ == '__main__':...
admin.py
Source: admin.py
1from django.contrib import admin2from .models import *3@admin.register(UserProfile)4class UserProfileAdmin(admin.ModelAdmin):5 list_display = ['get_username', 'phone', 'city', 'country']6 search_fields = ['get_username']7@admin.register(UserEducation)8class UserEducationAdmin(admin.ModelAdmin):9 list_display = ['get_username', 'degree', 'description', 'start_date', 'end_date']10 search_fields = ['get_username']11@admin.register(Hobby)12class HobbyAdmin(admin.ModelAdmin):13 list_display = ['name', 'image']14 search_fields = ['name']15@admin.register(UserPrivacy)16class HobbyAdmin(admin.ModelAdmin):17 list_display = ['get_username', 'profile_image', 'date_of_birth', 'phone_number', 'friends', 'search']18 search_fields = ['get_username']19@admin.register(UserHobby)20class HobbyAdmin(admin.ModelAdmin):21 list_display = ['get_username', 'get_hobby_name']...
Check out the latest blogs from LambdaTest on this topic:
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
Before we discuss the Joomla testing, let us understand the fundamentals of Joomla and how this content management system allows you to create and maintain web-based applications or websites without having to write and implement complex coding requirements.
The QA testing career includes following an often long, winding road filled with fun, chaos, challenges, and complexity. Financially, the spectrum is broad and influenced by location, company type, company size, and the QA tester’s experience level. QA testing is a profitable, enjoyable, and thriving career choice.
It’s strange to hear someone declare, “This can’t be tested.” In reply, I contend that everything can be tested. However, one must be pleased with the outcome of testing, which might include failure, financial loss, or personal injury. Could anything be tested when a claim is made with this understanding?
When it comes to UI components, there are two versatile methods that we can use to build it for your website: either we can use prebuilt components from a well-known library or framework, or we can develop our UI components from scratch.
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!!