├── extract ├── last_toot_id.txt └── script.py ├── airflow └── runner.py ├── mapreduce └── mr.py ├── load └── hbase.py ├── script.py ├── analyse └── script.py ├── README.md └── LICENSE /extract/last_toot_id.txt: -------------------------------------------------------------------------------- 1 | 111272741859448907 -------------------------------------------------------------------------------- /airflow/runner.py: -------------------------------------------------------------------------------- 1 | from airflow import DAG 2 | from airflow.operators.bash import BashOperator 3 | from datetime import datetime, timedelta 4 | 5 | default_args = { 6 | 'owner': 'tarifi', 7 | 'start_date': datetime(2023, 10, 24), 8 | 'retries': 1, 9 | 'retry_delay': timedelta(seconds=10), 10 | } 11 | 12 | # Create an instance of the DAG 13 | dag = DAG( 14 | 'task_to_run', 15 | default_args=default_args, 16 | description='Data pipeline for collecting and analyzing data from Mastodon', 17 | schedule_interval="@once", 18 | catchup=False, 19 | ) 20 | 21 | # Run Task to get data 22 | run_get_data = BashOperator( 23 | task_id='run_get_data_task', 24 | bash_command="python3 ~/repositories/Mastadon_HadoopAirflow/extract/script.py", 25 | dag=dag, 26 | ) 27 | 28 | # Task to run the Mapreduce script 29 | run_mapreducer = BashOperator( 30 | task_id='run_mapreducer_task', 31 | bash_command="python3 ~/repositories/Mastadon_HadoopAirflow/mapreduce/mr.py ~/repositories/Mastadon_HadoopAirflow/posts122152.json > ~/repositories/Mastadon_HadoopAirflow/output.txt", 32 | dag=dag, 33 | ) 34 | 35 | # TAsk to run the loading script 36 | run_inset_hbase = BashOperator( 37 | task_id='insert_into_hbase', 38 | bash_command='python3 ~/repositories/Mastadon_HadoopAirflow/load/hbase.py', 39 | dag=dag 40 | ) 41 | 42 | # Set task dependencies 43 | run_get_data >> run_mapreducer >> run_inset_hbase -------------------------------------------------------------------------------- /mapreduce/mr.py: -------------------------------------------------------------------------------- 1 | import json 2 | from mrjob.job import MRJob 3 | from mrjob.step import MRStep 4 | 5 | 6 | class WordCounter(MRJob): 7 | 8 | def mapper(self, _, line): 9 | post = json.loads(line) 10 | 11 | account_id = post["Account"]["id"] 12 | username = post["Account"]["username"] 13 | account_created_at = post["Account"]["created_at"] 14 | account_url = post["Account"]["url"] 15 | account_followers_count = post["Account"]["followers_count"] 16 | account_following_count = post["Account"]["following_count"] 17 | account_status_count = post["Account"]["statuses_count"] 18 | post_id = post["post_id"] 19 | post_favourites_count = post["favourites_count"] 20 | post_reblogs_count = post["reblogs_count"] 21 | post_visibility = post["visibility"] 22 | post_media = post["media_attachments"] 23 | language = post["language"] 24 | post_tags = post["tags"] 25 | 26 | # User values 27 | yield "username:"+str(account_id), username 28 | yield "created_at:"+str(account_id), account_created_at 29 | yield "followers_count:"+str(account_id), account_followers_count 30 | yield "following_count:"+str(account_id), account_following_count 31 | yield "status_count:"+str(account_id), account_status_count 32 | if len(account_url) > 1: 33 | yield "url:"+str(account_id), account_url 34 | else: 35 | yield "url:"+str(account_id), "None" 36 | # Post values 37 | yield "user_id:"+str(post_id), account_id 38 | yield "favourites_count:"+str(post_id), post_favourites_count 39 | yield "reblogs_count:"+str(post_id), post_reblogs_count 40 | yield "visibility:"+str(post_id), post_visibility 41 | if language: 42 | yield "language:"+str(post_id), language 43 | else: 44 | yield "language:"+str(post_id), "None" 45 | if post_tags: 46 | for tag in post_tags: 47 | yield "tag:"+str(post_id), tag["name"] 48 | yield "media:"+str(post_id), 1 if len(post_media) > 0 else 0 49 | 50 | def combiner(self, key, values): 51 | yield key,max(values) 52 | 53 | def reducer(self, key, values): 54 | yield key, max(values) 55 | 56 | 57 | def steps(self): 58 | return [ 59 | MRStep( 60 | mapper=self.mapper, 61 | reducer=self.reducer 62 | ) 63 | ] 64 | 65 | 66 | if __name__ == '__main__': 67 | WordCounter.run() 68 | -------------------------------------------------------------------------------- /load/hbase.py: -------------------------------------------------------------------------------- 1 | # import the libs 2 | from datetime import datetime 3 | import happybase 4 | 5 | 6 | # made connection with hbase on localhost:9090 7 | connection = happybase.Connection('127.0.0.1',9090) 8 | print("Connection was successfully established with the server.") 9 | 10 | # tables names 11 | user_table = 'user_table' 12 | post_table = 'post_table' 13 | 14 | # read the content of txt file included on the root. 15 | f = open("/home/TarifiHadoopAdmin/repositories/Mastadon_HadoopAirflow/output.txt", "r") 16 | 17 | 18 | # check if the tables exists. 19 | table_list = [t.decode('utf-8') for t in connection.tables()] 20 | 21 | # create the table if not exist (user table) 22 | if user_table not in table_list : 23 | connection.create_table( 24 | user_table, 25 | { 26 | 'user_details':dict() 27 | } 28 | ) 29 | print(f"Table {user_table} was successfully created.") 30 | 31 | # create the table if not exist (post table) 32 | if post_table not in table_list : 33 | connection.create_table( 34 | post_table, 35 | { 36 | 'post_details':dict() 37 | } 38 | ) 39 | print(f"Table {user_table} was successfully created.") 40 | 41 | # make connection to tables 42 | table_user = connection.table(user_table) 43 | table_post = connection.table(post_table) 44 | 45 | # insert into the tables 46 | for x in f: 47 | # get line from the content the text file splited by " 48 | item = x.split('"') 49 | # get the column name from the line 50 | column = item[1].split(':')[0] 51 | # get the row key from the line 52 | row_key = item[1].split(':')[1] 53 | # get the value from the line 54 | values = item[1].split(':')[0] 55 | if values == 'following_count' or values == 'followers_count' or values == 'status_count' or values == 'created_at' : 56 | if values == 'created_at': 57 | # convert datetime from millisecondes to "yyyy-MM-dd hh:mm:ss" 58 | created_at = datetime.fromtimestamp(int(item[2].strip()) / 1000) 59 | table_user.put(row_key, {"user_details:" + column:str(created_at)}) 60 | else: 61 | table_user.put(row_key, {"user_details:" + column:item[2].strip()}) 62 | elif values =='username'or values == 'url': 63 | table_user.put(row_key, {"user_details:" + column:item[3].strip()}) 64 | elif values == 'user_id' or values == 'media' or values == 'favourites_count' or values == 'reblogs_count': 65 | table_post.put(row_key, {"post_details:" + column:item[2].strip()}) 66 | elif values =='language' or values == 'tag' or values == 'visibility': 67 | table_post.put(row_key, {"post_details:" + column:item[3].strip()}) 68 | 69 | print("Data was inserted successfully.") 70 | 71 | # close connection to txt file and hbase 72 | f.close() 73 | connection.close() -------------------------------------------------------------------------------- /extract/script.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from datetime import datetime 3 | from mastodon import Mastodon 4 | from hdfs import InsecureClient 5 | from dotenv import load_dotenv 6 | import os 7 | 8 | 9 | # this function will pass through to the HDFS client write() 10 | def send_data_to_hdfs(df: pd.DataFrame): 11 | 12 | # Convert DataFrame to JSON format 13 | data = df.to_json(orient='records', lines=True) 14 | # json_data = json.dump(data) 15 | #json_bytes = data.encode('utf-8') 16 | 17 | user_name = 'TarifiHadoopAdmin' 18 | host = 'http://localhost:9870' 19 | 20 | # Connect to HDFS 21 | client = InsecureClient(host, user=user_name) 22 | 23 | hdfs_filepath = "/user/" + user_name + "/posts" + datetime.now().strftime('%d-%m-%Y') + ".json" 24 | 25 | # Upload the JSON data to HDFS 26 | with client.write(hdfs_filepath, overwrite=True) as hdfs_file: 27 | hdfs_file.write(data) 28 | 29 | 30 | # Load environment variables from .env 31 | load_dotenv() 32 | 33 | # Create Mastodon API client 34 | mastodon = Mastodon( 35 | client_id=os.getenv('Client_key'), 36 | client_secret=os.getenv('Client_secret'), 37 | access_token=os.getenv('Access_token'), 38 | api_base_url="https://mastodon.social" 39 | ) 40 | 41 | def get_posts(id): 42 | # toots = mastodon.timeline_hashtag(query,limit=10000) 43 | toots = mastodon.timeline_public(limit=10000,since_id=id) 44 | data = [] 45 | for toot in toots: 46 | posts_data = { 47 | 'post_id': toot['id'], 48 | 'account': toot['account'], 49 | 'content': toot['content'], 50 | 'created_at': toot['created_at'], 51 | 'favourites_count': toot['favourites_count'], 52 | 'reblogs_count': toot['reblogs_count'], 53 | 'sensitive': toot['sensitive'], 54 | 'visibility': toot['visibility'], 55 | 'mentions': toot['mentions'], 56 | 'media_attachments': toot['media_attachments'], 57 | 'tags': toot['tags'], 58 | 'emojis' : toot['emojis'], 59 | 'language': toot['language'], 60 | } 61 | data.append(posts_data) 62 | return data 63 | 64 | # iteration count 65 | count = 20 66 | 67 | # Extract posts and save it to hdfs 68 | print("Getting posts from API") 69 | 70 | posts_data = [] 71 | 72 | for i in range(count): 73 | # Specify the last toot id 74 | with open('/home/TarifiHadoopAdmin/repositories/Mastadon_HadoopAirflow/extract/last_toot_id.txt', 'r+') as file: 75 | last_toot_id = file.read().strip() 76 | 77 | if last_toot_id != '': 78 | last_toot_id = int(last_toot_id) 79 | else: 80 | last_toot_id = None 81 | 82 | # Get Data from Mastodon API 83 | data = get_posts(last_toot_id) 84 | posts_data += data 85 | 86 | # Save the last toot id 87 | with open('/home/TarifiHadoopAdmin/repositories/Mastadon_HadoopAirflow/extract/last_toot_id.txt', 'r+') as file: 88 | file.write(str(posts_data[-1]['post_id'])) 89 | 90 | posts_data = get_posts(last_toot_id) 91 | # Sending Files to hdfs 92 | print("Sending file to hdfs") 93 | df_posts = pd.DataFrame(posts_data) 94 | send_data_to_hdfs(df_posts) 95 | -------------------------------------------------------------------------------- /script.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | from datetime import datetime 3 | from mastodon import Mastodon 4 | from hdfs import InsecureClient 5 | from dotenv import load_dotenv 6 | import os 7 | 8 | 9 | # this function will pass through to the HDFS client write() 10 | def send_data_to_hdfs(df: pd.DataFrame, data_type: str): 11 | # Convert DataFrame to JSON format 12 | json_data = df.to_json(orient='records') 13 | json_bytes = json_data.encode('utf-8') 14 | 15 | user_name = 'TarifiHadoopAdmin' 16 | host = 'http://localhost:9870' 17 | 18 | # Connect to HDFS 19 | client = InsecureClient(host, user=user_name) 20 | 21 | if data_type == 'users': 22 | hdfs_filepath = "/user/" + user_name + "/" + datetime.now().strftime('%d%m%Y') + "/users" + datetime.now().strftime('%H%M%S') + ".json" 23 | elif data_type == 'posts': 24 | hdfs_filepath = "/user/" + user_name + "/" + datetime.now().strftime('%d%m%Y') + "/posts" + datetime.now().strftime('%H%M%S') + ".json" 25 | 26 | # Upload the JSON data to HDFS 27 | with client.write(hdfs_filepath, overwrite=True) as hdfs_file: 28 | hdfs_file.write(json_bytes) 29 | 30 | 31 | # Load environment variables from .env 32 | load_dotenv() 33 | 34 | # Get the access token (Create a .env file and add access_token variable in it) 35 | access_token = os.getenv('access_token') 36 | 37 | # Create Mastodon API client 38 | mastodon = Mastodon( 39 | api_base_url = 'https://mastodon.social', 40 | access_token = access_token, 41 | ) 42 | 43 | def search_users(): 44 | data = [] 45 | for char in 'abcdefghijklmnopqrstuvwxyz': 46 | results = mastodon.account_search(q=char) 47 | for user in results: 48 | user_data = { 49 | 'id': user['id'], 50 | 'username': user['username'], 51 | 'display_name': user['display_name'], 52 | 'is_group': user['group'], 53 | 'following_count': user['following_count'], 54 | 'followers_count': user['followers_count'], 55 | 'statuses_count': user['statuses_count'], 56 | 'bio': user['note'], 57 | 'is_bot': user['bot'], 58 | 'created_at': user['created_at'] 59 | } 60 | data.append(user_data) 61 | return data 62 | 63 | def get_posts(): 64 | # toots = mastodon.timeline_hashtag(query,limit=10000) 65 | toots = mastodon.timeline_public(limit=10000) 66 | data = [] 67 | for toot in toots: 68 | posts_data = { 69 | 'post_id': toot['id'], 70 | 'Account_id': toot['account']['id'], 71 | 'Content': toot['content'], 72 | 'Created_at': toot['created_at'], 73 | 'favourites_count': toot['favourites_count'], 74 | 'sensitive': toot['sensitive'], 75 | 'visibility': toot['visibility'], 76 | 'mentions': toot['mentions'], 77 | 'media_attachments': toot['media_attachments'], 78 | 'tags': toot['tags'], 79 | 'language': toot['language'], 80 | } 81 | data.append(posts_data) 82 | return data 83 | 84 | 85 | # Extract users and save it to hdfs 86 | print("Getting users from API") 87 | users_data = search_users() # search for users by a letter 88 | df_users = pd.DataFrame(users_data) 89 | 90 | # Sending Files to hdfs 91 | print("Sending file to hdfs") 92 | send_data_to_hdfs(df_users, 'users') 93 | 94 | # Extract posts and save it to hdfs 95 | print("Getting posts from API") 96 | # Extract posts and save it to hdfs 97 | posts_data = [] 98 | for i in range(100): 99 | posts = get_posts() # Get the toots 100 | for post in posts: 101 | posts_data.append(post) 102 | 103 | # Sending Files to hdfs 104 | print("Sending file to hdfs") 105 | df_posts = pd.DataFrame(posts_data) 106 | send_data_to_hdfs(df_posts, 'posts') 107 | -------------------------------------------------------------------------------- /analyse/script.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | import happybase 3 | 4 | # made connection with hbase on localhost:9090 5 | connection = happybase.Connection('127.0.0.1',9090) 6 | print("Connection was successfully established with the server.") 7 | 8 | # tables names 9 | user_table = 'user_table' 10 | post_table = 'post_table' 11 | 12 | # make connection to tables 13 | table_user = connection.table(user_table) 14 | table_post = connection.table(post_table) 15 | 16 | 17 | print("------------------------User with the highest followers------------------------------") 18 | 19 | 20 | # get data from table user 21 | rows = table_user.scan() 22 | 23 | # Initialize a dictionary to store user followers 24 | user_followers = {} 25 | 26 | # Iterate over the rows and store user followers 27 | for row_key, data in rows: 28 | followers_count = int(data[b'user_details:followers_count']) 29 | username = data[b'user_details:username'].decode('utf-8') 30 | 31 | user_followers[username] = followers_count 32 | 33 | # Sort users based on follower count 34 | sorted_users = sorted(user_followers.items(), key=lambda x: x[1], reverse=True) 35 | 36 | # Specify the number of top users you want to retrieve 37 | num_top_users = 5 38 | # Print the top users with the highest number of followers 39 | print(f"Top {num_top_users} users with the highest number of followers:") 40 | 41 | for i, (username, followers_count) in enumerate(sorted_users[:num_top_users]): 42 | print(f"{i+1}. User: {username} | Followers: {followers_count}") 43 | 44 | print("------------------------User engagement------------------------------") 45 | 46 | 47 | # Retrieve post data 48 | post_rows = table_post.scan() 49 | 50 | # Iterate over post rows 51 | for post_row_key, post_data in post_rows: 52 | # Extract relevant data from post data 53 | user_id = post_data[b'post_details:user_id'] #.decode('utf-8') 54 | reblogs_count = int(post_data[b'post_details:reblogs_count']) 55 | favourites_count = int(post_data[b'post_details:favourites_count']) 56 | 57 | 58 | # Retrieve user data from user_table 59 | user_data = table_user.row(user_id,columns=["user_details:followers_count", "user_details:username"]) 60 | # print(user_data) 61 | 62 | # Check if user data exists for the post 63 | if user_data: 64 | followers_count = int(user_data[b'user_details:followers_count']) 65 | username = user_data[b'user_details:username'].decode('utf-8') 66 | followers_count = 1 if followers_count == 0 else followers_count 67 | # Calculate engagement rate 68 | engagement_rate = (favourites_count + reblogs_count) / followers_count 69 | 70 | # Print the engagement rate for the user 71 | print(f"Engagement rate for user {username}: {round(engagement_rate*100,2)}%") 72 | else: 73 | print(f"No post data found for user {username}") 74 | 75 | 76 | print("------------------------User inscription------------------------------") 77 | 78 | # Retrieve user data 79 | user_rows = table_user.scan() 80 | 81 | # Dictionary to store user counts by month 82 | users_by_month = {} 83 | 84 | # Iterate over user rows 85 | for user_row_key, user_data in user_rows: 86 | # Extract the creation date of the user 87 | created_at = user_data[b'user_details:created_at'].decode('utf-8') 88 | 89 | # Parse the creation date string to datetime object 90 | created_at_date = datetime.strptime(created_at, '%Y-%m-%d %H:%M:%S') 91 | 92 | # Extract the month and year from the creation date 93 | month = created_at_date.strftime('%Y-%m') 94 | year = created_at_date.strftime('%Y') 95 | 96 | # Update the user count for the specific month 97 | if month in users_by_month: 98 | users_by_month[month] += 1 99 | else: 100 | users_by_month[month] = 1 101 | 102 | # sort values by count 103 | sorted_users_by_month = sorted(users_by_month.items(), key=lambda x: x[1], reverse=True) 104 | 105 | # Print the user counts by month 106 | for month, user_count in sorted_users_by_month: 107 | print(f"Month: {month}, User Count: {user_count}") 108 | 109 | # Close the HBase connection 110 | connection.close() 111 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Analysis of user interaction data on the Mastodon platform. 2 | 3 | ## Description: 4 | This project aims to analyze social media data to obtain information about user engagement, content popularity, etc.. 5 | It utilizes MapReduce for data processing, stores the results in HBase, and orchestrates the workflow using Apache Airflow. 6 | 7 | ## Data Source { Mastodon API }: 8 | [Mastodon](https://joinmastodon.org/) is a social media platform that operates on an open-source framework [Github doc](https://github.com/felx/mastodon-documentation). It boasts a comprehensive Application Programming Interface (API) that empowers developers to interact with various facets of the platform. Here's a succinct overview of the Mastodon API's key components: 9 | 10 | - Secure Authentication: Mastodon's API incorporates robust authentication methods, enabling developers to implement secure user authentication and access control. 11 | 12 | - User Account Management: The API facilitates the management of user accounts, encompassing tasks such as handling user profile data, preferences, and settings. 13 | 14 | - Toot Management: Developers can utilize the API to create, retrieve, and manage "toots" (equivalent to tweets in Mastodon), encompassing features such as posting, fetching, and deleting toots. 15 | 16 | - Notifications: The API offers access to notifications, enabling developers to fetch and manage various notifications, including mentions, likes, and reposts. 17 | 18 | - Timelines: Developers can leverage the API to access different timelines, such as the home timeline, local timeline, and federated timeline. This empowers them to retrieve and interact with posts from diverse timelines. 19 | 20 | - User Interactions: The API facilitates user interactions, encompassing functionalities like following/unfollowing users, liking toots, and reposting (boosting) content. 21 | 22 | - Search Functionality: Mastodon's API supports powerful search capabilities, enabling users to search for specific content, users, or hashtags within the Mastodon network. 23 | 24 | - Streaming Capabilities: The API offers streaming capabilities, allowing developers to implement real-time updates for activities such as new toots, notifications, and other interactions. 25 | 26 | - Instance and Federation Information: Mastodon's API provides valuable insights into instances and federation, enabling developers to retrieve data about instances, their policies, and the federated network of instances. 27 | 28 | ## Data Structure: 29 | 30 | | Data Type | Fields/Attributes | 31 | |------------------|---------------------------------------------------------------| 32 | | User Data | Username, Display Name, Bio, Avatar Image, Header Image, Follower Count, Following Count, Account Creation Date | 33 | | User Preferences | Privacy Settings, Notification Preferences, Account Visibility Options, Content Viewing Preferences | 34 | | Toots (Posts) | Toot ID, Content Text, Attached Media, Creation Timestamp, Visibility Settings, Content Tags, Reblogs (Boosts) Count, Likes (Favorites) Count, Mentioned Users | 35 | | Notifications | Notification ID, Notification Type, Related Toot ID, Timestamp, Notifying User | 36 | | Instance Data | Instance Name, Instance Description, Instance Rules and Policies, Instance Admins and Moderators | 37 | | Federation Data | Connected Instances, Federation Policies, Interaction Policies with External Instances | 38 | | Metadata | Hashtag Name, Associated Toots, Media ID, Media Type, Media URL, Language of the Toot | 39 | | Interaction Data | Follower ID, Followed User ID, User ID, Liked Toot ID, User ID, Boosted Toot ID | 40 | 41 | ## Tables schema 42 | ![image](https://github.com/Tarifi-Hicham/Mastadon_HadoopAirflow/assets/125143059/66033ae9-ef4e-40e7-b488-4f5879c82f33) 43 | 44 | ## Mission: 45 | As a data engineer, my primary objective is to maintain a robust big data pipeline capable of extracting data using the Mastodon API and storing it in Hadoop HDFS as JSON files. Subsequently, I will develop a MapReduce script to transform the data into key-value pairs. The processed data will be efficiently stored in HBase, enabling valuable insights to be derived from it. To ensure seamless and efficient workflow management, I will integrate Apache Airflow, a powerful platform for workflow orchestration and management. This integration will facilitate automated execution and real-time monitoring of the data analysis process, ensuring its effectiveness. 46 | 47 | ## Technologies: 48 | Apache hadoop, HBase, Airflow, Python. 49 | 50 | ## Gantt chart 51 | ![image](https://github.com/Tarifi-Hicham/Mastadon_HadoopAirflow/assets/125143059/aff59d6e-547f-4ac3-a3fe-ca30b24502b3) 52 | 53 | ## RGPD 54 | ### Data Privacy and GDPR Compliance 55 | 56 | This project is committed to ensuring the protection of personal data and compliance with the General Data Protection Regulation (GDPR). We prioritize the privacy and rights of our users and handle personal data in a responsible and transparent manner. 57 | 58 | Any personal data collected and processed by this project is done so in accordance with a valid lawful basis, such as user consent or legal obligations. We only collect and store necessary personal data for specific purposes, and we do not use the data for any other purposes without proper legal justification. 59 | 60 | We implement robust security measures to safeguard personal data from unauthorized access, loss, or disclosure. Our systems are regularly monitored and updated to maintain the highest level of data protection. 61 | 62 | ## Results of some analysis 63 | ### User top followers count 64 | ![image](https://github.com/Tarifi-Hicham/Mastadon_HadoopAirflow/assets/125143059/a0022fb4-e49a-49c2-8af9-e4477d708d4a) 65 | 66 | ### Users engagement 67 | ![image](https://github.com/Tarifi-Hicham/Mastadon_HadoopAirflow/assets/125143059/935db2b3-a1ca-4239-8de6-664b06806daa) 68 | 69 | ### Users inscription based on time 70 | ![image](https://github.com/Tarifi-Hicham/Mastadon_HadoopAirflow/assets/125143059/95011898-d455-417e-80ec-cf92a6ef3ef3) 71 | 72 | 73 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------