| 'Yes' | |
| if community_creation_admin_only == True: | |
| new_comm = "No" | |
| else: | |
| new_comm = "Yes" | |
| if federation_enabled == False or federated_allowed != []: | |
| fed = 'No' | |
| else: | |
| fed = "Yes" | |
| print( "\tfederation_enabled:|" +str(federation_enabled)+ "|" ) | |
| print( "\tfederated_allowed:|" +str(federated_allowed)+ "|" ) | |
| print( "\tfed:|" +str(fed)+ "|" ) | |
| if enable_downvotes == True: | |
| downvotes = "Yes" | |
| else: | |
| downvotes = "No" | |
| if registration_mode == "closed": | |
| new_users = "No" | |
| else: | |
| new_users = "Yes" | |
| # stupid way to say gimmie the 'uptime_alltime' data from the json where | |
| # the 'domain' matches this iteration lemmy instance's domain | |
| uptime = [x['uptime_alltime'] for x in uptime_data['data']['nodes'] if x['domain'] == domain] | |
| # stupid way to say gimmie the 'monthsmonitored' data from the json where | |
| # the 'domain' matches this iteration lemmy instance's domain | |
| age = [x['monthsmonitored'] for x in age_data['data']['nodes'] if x['domain'] == domain] | |
| # did we figure out an uptime for this domain? | |
| if uptime == []: | |
| # we couldn't find an uptime; set it to '??' | |
| uptime = '??' | |
| else: | |
| # we got an uptime! Format it for the table | |
| uptime = uptime[0] | |
| # let's keep the data simple | |
| uptime = round(float(uptime)) | |
| uptime = str(uptime)+ "%" | |
| # did we figure out an age for this domain? | |
| if age == []: | |
| # we couldn't find an uptime; set it to '??' | |
| age = '??' | |
| else: | |
| # we got an uptime! Format it for the table | |
| age = age[0] | |
| # let's keep the data simple | |
| age = round(float(age)) | |
| csv_contents += "[" +name+ "](https://" +domain+ ")," | |
| csv_contents += new_users+ "," | |
| csv_contents += new_comm+ "," | |
| csv_contents += fed+ "," | |
| csv_contents += adult+ "," | |
| csv_contents += downvotes+ "," | |
| csv_contents += str(users_month)+ ',' | |
| csv_contents += str(blocking)+ ',' | |
| csv_contents += str(blocked_by)+ ',' | |
| csv_contents += str(uptime)+ ',' | |
| csv_contents += str(age)+ ',' | |
| csv_contents += version | |
| csv_contents += "\n" | |
| # write the instance data table to the csv file | |
| with open( OUT_CSV, "w" ) as csv_file: | |
| csv_file.write( csv_contents ) | |
| ######################### | |
| # RECOMMENDED INSTANCES # | |
| ######################### | |
| # shrink the list to just a few recommended instances | |
| all_instances = list() | |
| recommended_instances = list() | |
| with open(OUT_CSV) as csv_file: | |
| for instance in csv.DictReader( csv_file ): | |
| all_instances.append( instance ) | |
| # only include instances that are "yes" across-the-board | |
| if instance['NU'] == "Yes" \ | |
| and instance['NC'] == "Yes" \ | |
| and instance['Fed'] == "Yes" \ | |
| and instance['Adult'] == "Yes" \ | |
| and instance['↓V'] == "Yes": | |
| recommended_instances.append( instance ) | |
| # remove instances with too few or too may users | |
| recommended_instances = [x for x in recommended_instances if int(x['Users']) > 60 and int(x['Users']) < 1000] | |
| # get a lits of all the instances that have more than 1 blocked instance and | |
| # then get the average number of instances that are blocked | |
| try: | |
| bi_list = [ int(x['BI']) for x in all_instances if int(x['BI']) > 1 ] | |
| bi_avg = numpy.average( bi_list ) | |
| except (Exception, RuntimeWarning) as e: | |
| print( "WARNING: Caught numpy exception when calculating bi_avg: " +str(e) ) | |
| bi_avg = 2 | |
| # get a lits of all the instances that are blocked by more than 1 instance and | |
| # then get the average number of that instances are are blocked | |
| try: | |
| bb_list = [ int(x['BB']) for x in all_instances if int(x['BB']) > 1 ] | |
| bb_avg = numpy.average( bb_list ) | |
| except (Exception, RuntimeWarning) as e: | |
| print( "WARNING: Caught numpy exception when calculating bb_avg: " +str(e) ) | |
| bb_avg = 2 | |
| print( "bi_avg:|" +str(bi_avg)+ "|" ) | |
| print( "bb_avg:|" +str(bb_avg)+ "|" ) | |
| # remove instances that are blocking or blocked-by too many other instancesk | |
| recommended_instances = [ x for x in recommended_instances if int(x['BI']) <= bi_avg and int(x['BB']) <= bb_avg ] | |
| # remove instances that haven't been online for 2 months | |
| recommended_instances = [ x for x in recommended_instances if int(x['MO']) >= 2 ] | |
| # limit to those with the best uptime; first we make sure that we actually | |
| # have the uptime data | |
| uptime_available = [x for x in recommended_instances if x['UT'] != '??'] | |
| # do we have uptime data? | |
| if uptime_available != list(): | |
| # we have uptime data; proceed with reducing the set of recommended_instances | |
| # based on uptime | |
| # loop down from 100% to 0% | |
| for percent_uptime in reversed(range(100)): | |
| high_uptime_instances = [x for x in recommended_instances if x['UT'] != '??' and int(x['UT'][:-1]) > percent_uptime] | |
| # do we have more than one instance above this uptime? | |
| if len(high_uptime_instances) > 1: | |
| # we already have enough instances; ignore the rest with lower uptime | |
| recommended_instances = high_uptime_instances | |
| break | |
| # prepare data for csv file | |
| csv_contents = "Instance,NU,NC,Fed,Adult,↓V,Users,BI,BB,UT,MO,Version\n" | |
| for instance in recommended_instances: | |
| csv_contents += instance['Instance']+ ',' | |
| csv_contents += instance['NU']+ ',' | |
| csv_contents += instance['NC']+ ',' | |
| csv_contents += instance['Fed']+ ',' | |
| csv_contents += instance['Adult']+ ',' | |
| csv_contents += instance['↓V']+ ',' | |
| csv_contents += instance['Users']+ ',' | |
| csv_contents += instance['BI']+ ',' | |
| csv_contents += instance['BB']+ ',' | |
| csv_contents += instance['UT']+ ',' | |
| csv_contents += instance['MO']+ ',' | |
| csv_contents += instance['Version'] | |
| csv_contents += "\n" | |
| # write the recommended instance data table to a csv file | |
| with open( 'recommended-instances.csv', "w" ) as csv_file: | |
| csv_file.write( csv_contents ) | |
| # convert csv file data to markdown table | |
| df = pd.read_csv( 'recommended-instances.csv' ) | |
| recommended_markdown_table = df.to_markdown( tablefmt='pipe', index = False ) | |
| # add newline to protect the table from getting klobbered by the text around it | |
| recommended_markdown_table = "\n" + recommended_markdown_table + "\n" | |
| readme_contents += """ | |
| # Recommended Instances | |
| Just **click on a random instance** from the below "recommended" instances. | |
| Don't overthink this. **It doesn't matter which instance you use.** You'll still be able to interact with communities (subreddits) on all other instances, regardless of which instance your account lives 🙂 | |
| """ | |
| # add the markdown table to the readme's contents | |
| readme_contents += recommended_markdown_table | |
| readme_contents += """ | |
| # What's next? | |
| ## Subscribe to ~~Subreddits~~ Communities | |
| After you pick an instance and register an account, you'll want to subscribe to communities. You can subscribe to "local" communities on your instance, and (if you chose an instance that isn't siloed) you can also subscribe to "remote" communities on other instances. | |
| To **find popular communities** across all lemmy instances in the fediverse, you can use the [Lemmy Community Browser](https://browse.feddit.de/) run by feddit.de. | |
| * https://browse.feddit.de/ | |
| If you want a more direct mapping of your favorite /r/subreddits to lemmy, checkout these sites: | |
| 1. [redditmigration.com](https://redditmigration.com/) | |
| 1. [sub.rehab](https://sub.rehab/?searchTerm=&visibleServices=lemmy&officialOnly=false&newOnly=false&favoriteOnly=false&sortBy=users_active_week) | |
| 1. yoasif's [Unofficial Subreddit Migration List](https://www.quippd.com/writing/2023/06/15/unofficial-subreddit-migration-list-lemmy-kbin-etc.html) | |
| <a href="https://tech.michaelaltfield.net/2023/06/11/lemmy-migration-find-subreddits-communities/"><img src="lemmy-migration-find-subreddits-communities.jpg" alt="How To Find Lemmy Communities" /></a> | |
| For more information, see my guide on [How to Find Popular Lemmy Communities](https://tech.michaelaltfield.net/2023/06/11/lemmy-migration-find-subreddits-communities/) | |
| ## Other links | |
| You may want to also checkout the following websites for more information about Lemmy | |
| * [Official Lemmy Documentation](https://join-lemmy.org/docs/en/index.html) | |
| * [Intro to Lemmy Guide](https://tech.michaelaltfield.net/2023/06/11/lemmy-migration-find-subreddits-communities/) - How to create a lemmy account, find, and subscribe-to popular communities | |
| * [Lemmy Community Browser](https://browse.feddit.de/) - List of all communities across all lemmy instances, sorted by popularity | |
| * [Lemmy Map](https://lemmymap.feddit.de) - Data visualization of lemmy instances | |
| * [The Federation Info](https://the-federation.info/platform/73) - Another table comparing lemmy instances (with pretty charts) | |
| * [Federation Observer](https://lemmy.fediverse.observer/list) - Yet another table comparing lemmy instances | |
| * [FediDB](https://fedidb.org/software/lemmy) - Yet another site comparing lemmy instances (with pretty charts) | |
| * [Lemmy Sourcecode](https://github.com/LemmyNet/lemmy) | |
| * [Jerboa (Official Android Client)](https://f-droid.org/packages/com.jerboa/) | |
| * [Mlem (iOS Client)](https://apps.apple.com/gb/app/mlem-for-lemmy/id6450543782) | |
| """ | |
| ################# | |
| # ALL INSTANCES # | |
| ################# | |
| # convert csv file data to markdown table | |
| df = pd.read_csv( OUT_CSV ) | |
| markdown_table = df.to_markdown( tablefmt='pipe', index = False ) | |
| # a |